Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

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

Fix #2948

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds explicit validation to detect and handle JPEG images that are missing the required SOS (Start of Scan) marker, fixing issue #2948. Previously, such malformed images could cause unexpected behavior; now they will throw a clear InvalidImageContentException.

  • Added a boolean flag to track whether the SOS marker is encountered during JPEG parsing
  • Added validation after stream parsing in both decode and identify code paths to throw an exception if SOS marker is missing
  • Added comprehensive test coverage for both decode and identify operations with a malformed test image

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/Images/Input/Jpg/issues/issue-2948-sos.jpg Test image file (stored in Git LFS) that is missing the SOS marker
tests/ImageSharp.Tests/TestImages.cs Added constant reference to the new test image
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs Added two test methods to verify that both decode and identify operations throw InvalidImageContentException for images missing SOS marker
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs Added hasSOSMarker field, set it when SOS marker is encountered, and added validation checks after ParseStream in both Decode and Identify methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JimBobSquarePants JimBobSquarePants merged commit 0b34bca into main Nov 21, 2025
13 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/fix-2948 branch November 21, 2025 07:35
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.

NullReferenceException while loading image

2 participants