Skip to content

Jpeg decoder fails with NullReferenceException from malformed image #2085

@br3aker

Description

@br3aker

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

Current main branch

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

Windows 10

.NET Framework version

Any supported

Description

Attached jpeg is manually malformed image which doesn't even have a single SOS marker - it ends on incomplete DHT marker which lack a single byte.

However, decoder fails with NullReferenceException at unexpected place - in spectral -> pixel conversion code.

Stacktrace:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.JpegComponentPostProcessor.CopyBlocksToColorBuffer(Int32 spectralStep) in ...\ImageSharp\src\ImageSharp\Formats\Jpeg\Components\Decoder\JpegComponentPostProcessor.cs:line 88
...

Steps to Reproduce

using var img = Image.Load<Rgba32>(path);

Images

corrupted image.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions