Visitar URL original
Skip invalid markers during jpeg decoding by br3aker · Pull Request #2147 · SixLabors/ImageSharp · GitHub
Skip to content

Skip invalid markers during jpeg decoding - #2147

Merged
brianpopow merged 3 commits into
SixLabors:mainfrom
br3aker:dp/jpeg-decoder-invalid-marker-fix
Jun 6, 2022
Merged

brianpopow merged 3 commits into
SixLabors:mainfrom
br3aker:dp/jpeg-decoder-invalid-marker-fix

Conversation

@br3aker

@br3aker br3aker commented Jun 5, 2022

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #2136

Given image contained extra unused bytes right at the end of the SOS segment containing RST markers and 0xFF00 sequences. This lead to non-SOS parser to count them as valid markers and failed with exception. With this PR jpeg decoder now skips any invalid markers during non-SOS parsing so we can at least give the user something instead of exception.

// Read on.
fileMarker = FindNextFileMarker(this.markerBuffer, stream);
fileMarker = FindNextFileMarker(stream);
Console.WriteLine($"Found marker: {fileMarker.Marker} at {fileMarker.Position}");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Console.WriteLine is probably a leftover from debugging

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups!

@brianpopow brianpopow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@brianpopow
brianpopow merged commit e7a10b0 into SixLabors:main Jun 6, 2022
@br3aker
br3aker deleted the dp/jpeg-decoder-invalid-marker-fix branch June 8, 2022 05:42
This was referenced Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants