SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.39k stars 851 forks source link

AccessViolationException when loading corrupt GIF #2743

Closed Erik-White closed 3 months ago

Erik-White commented 4 months ago

Prerequisites

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