Imagesharp: NRE on JPEG image loading

Created on 12 Apr 2019  路  3Comments  路  Source: SixLabors/ImageSharp

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] 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
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description


Exception on loading specific JPEG image

Steps to Reproduce

using (Image.Load(@"D:\error.jpeg")) { }

with image error.zip will cause a NullReferenceException with message: Object reference not set to an instance of an object.
Here's the stacktrace:

   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JpegFrame.Dispose()
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.Dispose()
   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, String path)
   at ImageSharpTest.Program.Main(String[] args) in C:\Users\user\Documents\ImageSharpTest\Program.cs:line 13

System Configuration

  • ImageSharp version: 1.0.0-beta0006
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Windows 10.0.17763
  • .NET Framework version: netcoreapp2.0
  • Additional information:
bug jpeg

All 3 comments

@xakep139 Thanks for the detail. Does this happen with the nightlies?

With 1.0.0-dev002497 I get SixLabors.ImageSharp.ImageFormatException with message Unsupported color mode. Max components 4; found 3

Stacktrace:

   at SixLabors.ImageSharp.Formats.Jpeg.JpegThrowHelper.ThrowImageFormatException(String errorMessage)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.DeduceJpegColorSpace()
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.ProcessStartOfFrameMarker(Int32 remaining, JpegFileMarker& frameMarker, Boolean metadataOnly)
   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, String path)
   at ImageSharpTest.Program.Main(String[] args) in C:\Users\user\Documents\ImageSharpTest\Program.cs:line 13

@xakep139 Thanks, yeah that makes sense.

This is a badly encoded image. The App14 header is incorrectly reporting the colorspace as YccK yet there are only 3 color components. We throw, but since, this is an optional marker we are being too aggressive in doing so.

We should actually invert our approach and base our colorspace detection on defaults based on the component count and only change from the default if the component count is correct for any additonal metadata supplied.

Was this page helpful?
0 / 5 - 0 ratings