Skip to content

InvalidImageContentException "Input stream does not have enough bytes to parse declared contents of the 00 marker" when loading JPG created by Brother scanner #2136

@w-michal

Description

@w-michal

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

2.1.2

Other ImageSharp packages and versions

N/A

Environment (Operating system, version and so on)

Windows 10 x64, 21H2

.NET Framework version

net6.0

Description

Looks like my scanner (Brother 920dw) creates broken JPEGs by default...

Call stack

An unhandled exception of type 'SixLabors.ImageSharp.InvalidImageContentException' occurred in SixLabors.ImageSharp.dll: 'Input stream does not have enough bytes to parse declared contents of the 00 marker.'
   at SixLabors.ImageSharp.Formats.Jpeg.JpegThrowHelper.ThrowNotEnoughBytesForMarker(Byte marker)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.ParseStream(BufferedReadStream stream, HuffmanScanDecoder scanDecoder, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoderCore.Decode[TPixel](BufferedReadStream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, Func`3 largeImageExceptionFactory, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderUtilities.Decode[TPixel](IImageDecoderInternals decoder, Configuration configuration, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode[TPixel](Configuration configuration, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Jpeg.JpegDecoder.Decode(Configuration configuration, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Image.Decode(Stream stream, Configuration config, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Image.<>c__DisplayClass134_0.<Load>b__0(Stream s)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration configuration, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load(Configuration configuration, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load(Configuration configuration, String path, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load(Configuration configuration, String path)
   at SixLabors.ImageSharp.Image.Load(String path)

On top of that, ImageMagik reports more warnings. Command identify.exe -regard-warnings IMG_0012.JPG output:

IMG_0012.JPG JPEG 2544x3312 2544x3312+0+0 8-bit sRGB 826538B 0.047u 0:00.062
identify.exe: Corrupt JPEG data: 1418 extraneous bytes before marker 0xd7 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1200 extraneous bytes before marker 0xd0 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1169 extraneous bytes before marker 0xd1 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1169 extraneous bytes before marker 0xd2 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 4197 extraneous bytes before marker 0xd3 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1418 extraneous bytes before marker 0xd4 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1200 extraneous bytes before marker 0xd5 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1169 extraneous bytes before marker 0xd6 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.
identify.exe: Corrupt JPEG data: 1169 extraneous bytes before marker 0xd9 `IMG_0012.JPG' @ warning/jpeg.c/JPEGWarningHandler/403.

Steps to Reproduce

Call Image.Load on provided image.

Images

IMG_0012.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions