[IMAGING-333] Fix IndexOutOfBoundsException in JpegImageParser.getImageInfo() when no SOF segment is present - #557
Open
akashchamp wants to merge 1 commit into
Conversation
…geInfo() readSegments() never returns null; when a JPEG has no SOF (Start Of Frame) segment it returns an empty list instead. getImageInfo() only checked SOF_segments == null before calling SOF_segments.get(0), so the empty-list case threw an unchecked IndexOutOfBoundsException rather than the intended ImagingException. getImageSize(), a few lines below, already guards against this with `abstractSegments == null || abstractSegments.isEmpty()`. Apply the same guard to getImageInfo(). Add JpegWithoutSofSegmentTest, mirroring the existing JpegWithInvalidDhtSegmentTest, asserting that a minimal JPEG with no SOF segment causes Imaging.getImageInfo() to throw ImagingException. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mvn).What
JpegImageParser.getImageInfo()throws an uncheckedIndexOutOfBoundsExceptioninstead ofImagingExceptionwhen the JPEG has no SOF (Start Of Frame) segment.Why
readSegments()never returnsnull; when no SOF marker is present it returns an empty list.getImageInfo()only checkedSOF_segments == nullbefore immediately callingSOF_segments.get(0), so the empty-list case fell through to anIndexOutOfBoundsException. The sibling methodgetImageSize(), a few lines below, already guards against exactly this withabstractSegments == null || abstractSegments.isEmpty(). This PR applies the same guard togetImageInfo().Fixes IMAGING-333.
How
JpegImageParser.getImageInfo(): extend the SOF-segment guard to also checkisEmpty(), matchinggetImageSize(), and throw the existingImagingException("No SOFN Data Found.")instead.JpegWithoutSofSegmentTest, mirroring the existingJpegWithInvalidDhtSegmentTest, with a minimal 4-byte JPEG (SOI+EOI, no segments) assertingImaging.getImageInfo()throwsImagingException.Verification
IndexOutOfBoundsExceptionon currentmasterby running the new test before applying the fix.mvn -Dtest=JpegWithoutSofSegmentTest testpasses.mvn testsuite.