Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated Gif convertation fails with "unexpected EOF" #643

Open
FlipSs opened this issue Jun 8, 2021 · 7 comments
Open

Repeated Gif convertation fails with "unexpected EOF" #643

FlipSs opened this issue Jun 8, 2021 · 7 comments
Labels

Comments

@FlipSs
Copy link

FlipSs commented Jun 8, 2021

Hello!

Steps to reproduce:

  1. Resize some gif image
  2. Resize output from first step

Example gif:
https://media2.giphy.com/media/BLjVY7KIN1fYLLvkLh/giphy.gif?cid=ecf05e472d5ea09f14d415d582fe28c7665c258b75644605&rid=giphy.gif&ct=g

Example code:

public class Test 
{
                public async Task<byte[]> ConvertAsync(byte[] image)
		{
			using var imageSource = new BytesSource(image);

			using var job = new ImageJob();

			var node = job.Decode(
				imageSource,
				new DecodeCommands().SetIgnoreColorProfileErrors(true)
			);

			await using var resultStream = new MemoryStream();

			await node.Constrain(new Constraint(200, 100))
			.EncodeToStream(resultStream, false, new GifEncoder())
			.Finish()
			.InProcessAsync()
			.ConfigureAwait(false);

			return resultStream.ToArray();
		}

		public async Task Test(byte[] gif)
		{
			var converted = await ConvertAsync(gif);
			await ConvertAsync(converted); // throws error
		}
}

Error: Exception: Imageflow.Bindings.ImageflowException Error: ImageMalformed: "unexpected EOF" at imageflow_core/src/codecs/gif/mod.rs:57:91 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/codecs/gif/mod.rs#L57 imageflow_core/src/codecs/gif/mod.rs:162:54 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/codecs/gif/mod.rs#L162 imageflow_core/src/flow/nodes/codecs_and_pointer.rs:222:65 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/flow/nodes/codecs_and_pointer.rs#L222 imageflow_core/src/flow/execution_engine.rs:477:114 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/flow/execution_engine.rs#L477 imageflow_core/src/context.rs:419:59 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/context.rs#L419 imageflow_core/src/context_methods.rs:50:68 https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core/src/context_methods.rs#L50

@lilith
Copy link
Member

lilith commented Jun 25, 2021 via email

@FlipSs
Copy link
Author

FlipSs commented Jun 25, 2021

Hi, here are 2 resize steps, they are the same because this is an example, but the second is executed on the result of the first.

public async Task Test(byte[] gif)
{
        // first resize 
	var converted = await ConvertAsync(gif);
	// second resize
	await ConvertAsync(converted); // throws error
}

@lilith
Copy link
Member

lilith commented Jun 25, 2021 via email

@FlipSs
Copy link
Author

FlipSs commented Jun 25, 2021

doesn't work either

@ajbeaven
Copy link

ajbeaven commented Nov 2, 2021

I think I may be hitting something related to this with imageflow-dotnet-server too.

Here's an example GIF I got off Google Images that when stored in Azure Storage (don't think this is relevant) and referenced by imageflow-dotnet-server, fails to render correctly:

4016070_24725e92-1b64-4c96-b927-2b2ed2e2452b

Stack trace for this error:

Imageflow.Bindings.ImageflowException: ImageMalformed: "unexpected EOF" at
imageflow_core\src\codecs\gif\mod.rs:57:91
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\codecs\gif\mod.rs#L57
imageflow_core\src\codecs\gif\mod.rs:162:54
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\codecs\gif\mod.rs#L162
imageflow_core\src\flow\nodes\codecs_and_pointer.rs:222:65
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\flow\nodes\codecs_and_pointer.rs#L222
imageflow_core\src\flow\execution_engine.rs:477:114
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\flow\execution_engine.rs#L477
imageflow_core\src\context.rs:419:59
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\context.rs#L419
imageflow_core\src\context_methods.rs:50:68
https://github.com/imazen/imageflow/blob/1f6dc67eef41132d5d3300676daa5d42ae7f8941/imageflow_core\src\context_methods.rs#L50
Active node:
NodeDebugInfo {
    stable_id: 464,
    params: Json(
        Decode {
            io_id: 0,
            commands: None,
        },
    ),
    index: NodeIndex(1),
}


   at Imageflow.Bindings.JobContext.AssertReady()
   at Imageflow.Bindings.JobContext.SendJsonBytes(String method, Byte[] utf8Json)
   at Imageflow.Bindings.JobContext.Execute[T](T message)
   at Imageflow.Fluent.ImageJob.FinishAsync(JobExecutionOptions executionOptions, SecurityOptions securityOptions, CancellationToken cancellationToken)
   at Imageflow.Server.ImageJobInfo.ProcessUncached()
   at Imageflow.Server.ImageflowMiddleware.<>c__DisplayClass15_0.<<ProcessWithStreamCache>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Imazen.HybridCache.AsyncCache.<>c__DisplayClass35_0.<<GetOrCreateBytes>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Imazen.Common.Concurrency.AsyncLockProvider.TryExecuteAsync(String key, Int32 timeoutMs, CancellationToken cancellationToken, Func`1 success)
   at Imazen.HybridCache.AsyncCache.GetOrCreateBytes(Byte[] key, AsyncBytesResult dataProviderCallback, CancellationToken cancellationToken, Boolean retrieveContentType)
   at Imazen.HybridCache.HybridCache.GetOrCreateBytes(Byte[] key, AsyncBytesResult dataProviderCallback, CancellationToken cancellationToken, Boolean retrieveContentType)
   at Imageflow.Server.ImageflowMiddleware.ProcessWithStreamCache(HttpContext context, String cacheKey, ImageJobInfo info)
   at Imageflow.Server.ImageflowMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@lilith lilith added the bug label May 14, 2022
@lilith
Copy link
Member

lilith commented Sep 29, 2022

I think this is a codec problem: image-rs/image-gif#138

@lilith
Copy link
Member

lilith commented Feb 3, 2023

The "big hug" image is malformed, and the codec I use doesn't support recovering from that (yet).

$ # /usr/bin/giftopnm is owned by netpbm 10.73.37-2
$ giftopnm /tmp/139770827-18e25c4e-eb0a-4058-ba48-ddc3849090ee.gif > /dev/null 
giftopnm: Error accessing Image 67 of stream.  File read error where start of image descriptor or end of GIF expected.  End of file encountered

@lilith lilith transferred this issue from imazen/imageflow-dotnet Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants