Skip to content

NRE on JPEG image loading #882

Closed

Description

@xakep139

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

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:

Activity

  1. JimBobSquarePants commented on Apr 12, 2019

    @JimBobSquarePants
    Member

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

  2. xakep139 commented on Apr 12, 2019

    @xakep139
    ContributorAuthor

    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
    
  3. JimBobSquarePants commented on Apr 12, 2019

    @JimBobSquarePants
    Member

    @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.

  4. added this to the 1.0.0-rc1 milestone on Apr 12, 2019
  5. added a commit that references this issue on Apr 15, 2019
    998d9be
  6. added a commit that references this issue on Apr 15, 2019
    5a85ea7
  7. added a commit that references this issue on Aug 25, 2019
    9773e61
  8. added a commit that references this issue on Nov 11, 2019
    82d4384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions