RFR: 8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index [v2]
Jayathirth D V
jdv at openjdk.org
Thu Aug 21 05:06:53 UTC 2025
On Tue, 29 Jul 2025 17:22:09 GMT, Phil Race <prr at openjdk.org> wrote:
>> Jayathirth D V has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
>>
>> - Update test to handle all regression cases
>> - Add checks at other places also
>> - Merge remote-tracking branch 'upstream/master' into jpeg_getImageTypes
>> - Check only for negative index
>> - 8364135: JPEGImageReader.getImageTypes() should throw exception for non-zero image index
>
> src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java line 907:
>
>> 905: if (imageIndex != 0) {
>> 906: throw new IndexOutOfBoundsException("imageIndex != 0!");
>> 907: }
>
> There are JPEG streams with > 1.
> And elsewhere we handle it. Look at hasNextImage()
>
> Is this method the sole place where -1 would not throw the right exception ?
Thanks for the inputs.
getWidth(), getHeight(), getRawImageType() also need similar check.
What i have noticed is for all negative indices apart from "-1" we end up in gotoImage() function and it throws appropriate exception. Only getWidth(), getHeight(), getRawImageType() & getImageTypes() we don't throw proper exception according to spec when "-1" index is used. Also in case of getRawImageType() we actually throw NPE when "-1" index is passed.
So i have updated the code to add additional check for negative index at these places also.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26522#discussion_r2289860006
More information about the client-libs-dev
mailing list