RFR: 8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index [v3]
Alexey Ivanov
aivanov at openjdk.org
Mon Aug 25 14:19:03 UTC 2025
On Mon, 25 Aug 2025 09:53:10 GMT, Jayathirth D V <jdv at openjdk.org> wrote:
>> We need to throw appropriate exception when we pass invalid image index values to ImageReader.getImageTypes().
>> We throw IOOBE in all other plugins except JPEG, Added appropriate check to throw IOOBE when JpegImageReader has invalid image index.
>
> Jayathirth D V has updated the pull request incrementally with one additional commit since the last revision:
>
> Update image index verification function name
Changes requested by aivanov (Reviewer).
src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java line 848:
> 846: public int getWidth(int imageIndex) throws IOException {
> 847: verifyImageIndex(imageIndex);
> 848: setThreadLock();
I wonder whether accessing `minIndex` inside `verifyImageIndex` requires a lock.
test/jdk/javax/imageio/plugins/jpeg/JpegNegativeImageIndexTest.java line 24:
> 22: */
> 23:
> 24: /**
Suggestion:
/*
Let us not use the javadoc comment syntax for jtreg tags.
test/jdk/javax/imageio/plugins/jpeg/JpegNegativeImageIndexTest.java line 60:
> 58: ImageTypeSpecifier specifier = ir.getRawImageType(-1);
> 59: } catch (IndexOutOfBoundsException e) {
> 60: if (Objects.equals(e.getMessage(), "imageIndex < 0")) {
If we don't iterate over all readers but only the first one, throw the error before the `catch` block.
Inside the catch block, if the message isn't equal to the expected one, throw the error right away.
This allows removing indirection of using the `passed` field.
-------------
PR Review: https://git.openjdk.org/jdk/pull/26522#pullrequestreview-3151661604
PR Review Comment: https://git.openjdk.org/jdk/pull/26522#discussion_r2298230149
PR Review Comment: https://git.openjdk.org/jdk/pull/26522#discussion_r2298226685
PR Review Comment: https://git.openjdk.org/jdk/pull/26522#discussion_r2298240296
More information about the client-libs-dev
mailing list