Skip to content

Image.Load throws ArgumentOutOfRangeException #825

Closed
@Metalnem

Description

@Metalnem

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

Description

Image.Load throws ArgumentOutOfRangeException when loading malformed JPG file.

Steps to Reproduce

Run the following code snippet with the path variable containing the path to one of the files from the attached archive:

Image.Load(path);

There are four different stack traces in total for this exception type, which is why I bundled them together in a single issue (also, I'm not sure which one of these might be the part of the same issue, because some stack traces look quite similar). Here are all the stack traces:

Image 1

System.ArgumentOutOfRangeException: Value 0 must be greater than 0.
Parameter name: width
   at SixLabors.ImageSharp.Guard.ThrowArgumentOutOfRangeException(String parameterName, String message)
   at SixLabors.ImageSharp.ImageFrame`1..ctor(Configuration configuration, Int32 width, Int32 height, MemorySource`1 memorySource, ImageFrameMetaData metaData)
   at SixLabors.ImageSharp.ImageFrameCollection`1..ctor(Image`1 parent, Int32 width, Int32 height, MemorySource`1 memorySource)
   at SixLabors.ImageSharp.Image`1..ctor(Configuration configuration, MemorySource`1 memorySource, Int32 width, Int32 height, ImageMetaData metadata)
   at SixLabors.ImageSharp.Image.CreateUninitialized[TPixel](Configuration configuration, Int32 width, Int32 height, ImageMetaData metadata)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.PostProcessIntoImage[TPixel]()
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream)
   at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Byte[] data)

Image 2

System.ArgumentOutOfRangeException: Value 129 must be greater than or equal to 0 and less than or equal to 2.
Parameter name: densityUnits
   at SixLabors.ImageSharp.Guard.ThrowArgumentOutOfRangeException(String parameterName, String message)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JFifMarker..ctor(Byte majorVersion, Byte minorVersion, Byte densityUnits, Int16 xDensity, Int16 yDensity)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JFifMarker.TryParse(Byte[] bytes, JFifMarker& marker)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.ProcessApplicationHeaderMarker(Int32 remaining)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.ParseStream(Stream stream, Boolean metadataOnly)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.Decode[TPixel](Stream stream)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream)
   at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Byte[] data)

Image 3

System.ArgumentOutOfRangeException: Value 0 must be greater than 0.
Parameter name: height
   at SixLabors.ImageSharp.Guard.ThrowArgumentOutOfRangeException(String parameterName, String message)
   at SixLabors.ImageSharp.ImageFrame`1..ctor(Configuration configuration, Int32 width, Int32 height, MemorySource`1 memorySource, ImageFrameMetaData metaData)
   at SixLabors.ImageSharp.ImageFrameCollection`1..ctor(Image`1 parent, Int32 width, Int32 height, MemorySource`1 memorySource)
   at SixLabors.ImageSharp.Image`1..ctor(Configuration configuration, MemorySource`1 memorySource, Int32 width, Int32 height, ImageMetaData metadata)
   at SixLabors.ImageSharp.Image.CreateUninitialized[TPixel](Configuration configuration, Int32 width, Int32 height, ImageMetaData metadata)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.PostProcessIntoImage[TPixel]()
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream)
   at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Byte[] data)

Image 4

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters.JpegColorConverter.ComponentValues.Slice(Int32 start, Int32 length)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters.JpegColorConverter.FromYCbCrSimdAvx2.ConvertToRgba(ComponentValues& values, Span`1 result)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JpegImagePostProcessor.ConvertColorsInto[TPixel](ImageFrame`1 destination)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JpegImagePostProcessor.DoPostProcessorStep[TPixel](ImageFrame`1 destination)
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JpegImagePostProcessor.PostProcess[TPixel](ImageFrame`1 destination)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.PostProcessIntoImage[TPixel]()
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream)
   at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Byte[] data)

System Configuration

  • ImageSharp version: Beta 6
  • Environment (Operating system, version and so on): Windows 10 Pro 1803
  • .NET Framework version: .NET Core 2.2.102

Found via SharpFuzz.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions