akashchamp opened a new pull request, #557: URL: https://github.com/apache/commons-imaging/pull/557
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html). - [x] I used AI to create part of this pull request: Claude (Anthropic, via Claude Code) helped locate the root cause, write the one-line fix and the regression test. I reviewed, verified and take responsibility for the change. - [x] Ran a successful build using the default Maven goal (`mvn`). - [x] Added a unit test that fails without the fix and passes with it. - [x] Wrote a pull request description that explains what/how/why. - [x] Each commit has a meaningful subject line and body. ## What `JpegImageParser.getImageInfo()` throws an unchecked `IndexOutOfBoundsException` instead of `ImagingException` when the JPEG has no SOF (Start Of Frame) segment. ## Why `readSegments()` never returns `null`; when no SOF marker is present it returns an **empty** list. `getImageInfo()` only checked `SOF_segments == null` before immediately calling `SOF_segments.get(0)`, so the empty-list case fell through to an `IndexOutOfBoundsException`. The sibling method `getImageSize()`, a few lines below, already guards against exactly this with `abstractSegments == null || abstractSegments.isEmpty()`. This PR applies the same guard to `getImageInfo()`. Fixes [IMAGING-333](https://issues.apache.org/jira/browse/IMAGING-333). ## How - `JpegImageParser.getImageInfo()`: extend the SOF-segment guard to also check `isEmpty()`, matching `getImageSize()`, and throw the existing `ImagingException("No SOFN Data Found.")` instead. - Added `JpegWithoutSofSegmentTest`, mirroring the existing `JpegWithInvalidDhtSegmentTest`, with a minimal 4-byte JPEG (`SOI` + `EOI`, no segments) asserting `Imaging.getImageInfo()` throws `ImagingException`. ## Verification - Reproduced the reported `IndexOutOfBoundsException` on current `master` by running the new test before applying the fix. - After the fix, `mvn -Dtest=JpegWithoutSofSegmentTest test` passes. - Ran the full `mvn test` suite. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
