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

AccessViolationException when loading corrupt GIF #2743

Closed
4 tasks done
Erik-White opened this issue May 30, 2024 · 0 comments · Fixed by #2749
Closed
4 tasks done

AccessViolationException when loading corrupt GIF #2743

Erik-White opened this issue May 30, 2024 · 0 comments · Fixed by #2749

Comments

@Erik-White
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.4

Other ImageSharp packages and versions

N/A

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

.NET 8.0.4

Description

Opening the attached GIF causes an AccessViolatonException, and then a long hang (up to an hour) while the process tries to read GC information.

CoreCLR Version: 8.0.424.16909
.NET Version: 8.0.4
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException: Arg_AccessViolationException
Stack:
   at System.Resources.ResourceManager.GetFirstResourceSet(System.Globalization.CultureInfo)
   at System.Resources.ResourceManager.GetString(System.String, System.Globalization.CultureInfo)
   at System.SR.InternalGetResourceString(System.String)
   at System.SR.GetResourceString(System.String)
   at System.Exception.ToString()
   at System.Buffers.SharedArrayPool`1[[System.Char, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Rent(Int32)
   at System.Runtime.CompilerServices.DefaultInterpolatedStringHandler..ctor(Int32, Int32)
   at System.SR.InternalGetResourceString(System.String)
   at System.SR.GetResourceString(System.String)
   at System.AccessViolationException..ctor()
   at System.Resources.ResourceManager.GetFirstResourceSet(System.Globalization.CultureInfo)
   at System.Resources.ResourceManager.GetString(System.String, System.Globalization.CultureInfo)
   at System.SR.InternalGetResourceString(System.String)
   at System.SR.GetResourceString(System.String)
   at System.AccessViolationException..ctor()
   at System.Collections.Generic.List`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Add(System.__Canon)
   at SixLabors.ImageSharp.Formats.Gif.GifDecoderCore.ReadFrameMetadata(SixLabors.ImageSharp.IO.BufferedReadStream, System.Collections.Generic.List`1<SixLabors.ImageSharp.Metadata.ImageFrameMetadata>, SixLabors.ImageSharp.Metadata.ImageFrameMetadata ByRef)
   at SixLabors.ImageSharp.Formats.Gif.GifDecoderCore.Identify(SixLabors.ImageSharp.IO.BufferedReadStream, System.Threading.CancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Identify(SixLabors.ImageSharp.Formats.IImageDecoderInternals, SixLabors.ImageSharp.Configuration, System.IO.Stream, System.Threading.CancellationToken)
   at SixLabors.ImageSharp.Formats.Gif.GifDecoder.Identify(SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream, System.Threading.CancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoder+<>c__DisplayClass4_0.<Identify>b__0(System.IO.Stream)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<WithSeekableStream>g__PeformActionAndResetPosition|11_0[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.IO.Stream, Int64, <>c__DisplayClass11_0`1<System.__Canon> ByRef)
   at SixLabors.ImageSharp.Formats.ImageDecoder.WithSeekableStream[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream, System.Func`2<System.IO.Stream,System.__Canon>)
   at SixLabors.ImageSharp.Formats.ImageDecoder.Identify(SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream)
   at SixLabors.ImageSharp.Image.InternalIdentify(SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream)
   at SixLabors.ImageSharp.Image+<>c__DisplayClass76_0.<Identify>b__0(System.IO.Stream)
   at SixLabors.ImageSharp.Image.WithSeekableStream[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream, System.Func`2<System.IO.Stream,System.__Canon>)
   at SixLabors.ImageSharp.Image.Identify(SixLabors.ImageSharp.Formats.DecoderOptions, System.IO.Stream)
   at SixLabors.ImageSharp.Image.Identify(System.IO.Stream)

Steps to Reproduce

Try to read the image e.g.
var imageInfo = Image.Identify("9A71AFA18DE4DB335FCDF07CC6F88ED9.gif");
or
using var image = Image.Load("9A71AFA18DE4DB335FCDF07CC6F88ED9.gif");

Images

9A71AFA18DE4DB335FCDF07CC6F88ED9

JimBobSquarePants added a commit that referenced this issue Jun 7, 2024
* Limit lzw bits to a maximum of 12 bits, fixes issue #2743

* Dispose currentLocalColorTable in final block

* Revert "Dispose currentLocalColorTable in final block"

This reverts commit 35ea961.

* Don't throw; return.

---------

Co-authored-by: James Jackson-South <james_south@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants