Skip to content

8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index #26522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jayathirthrao
Copy link
Member

@jayathirthrao jayathirthrao commented Jul 29, 2025

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26522/head:pull/26522
$ git checkout pull/26522

Update a local copy of the PR:
$ git checkout pull/26522
$ git pull https://git.openjdk.org/jdk.git pull/26522/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26522

View PR using the GUI difftool:
$ git pr show -t 26522

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26522.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 29, 2025

👋 Welcome back jdv! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 29, 2025

@jayathirthrao This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index

Reviewed-by: prr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 158 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 29, 2025
@openjdk
Copy link

openjdk bot commented Jul 29, 2025

@jayathirthrao The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Jul 29, 2025

Webrevs

@@ -902,6 +902,9 @@ public ImageTypeSpecifier getRawImageType(int imageIndex)
@Override
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
throws IOException {
if (imageIndex != 0) {
throw new IndexOutOfBoundsException("imageIndex != 0!");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@jayathirthrao jayathirthrao changed the title 8364135: JPEGImageReader.getImageTypes() should throw exception for non-zero image index 8364135: JPEGImageReader.getImageTypes() should throw exception for negative image index Aug 20, 2025
@jayathirthrao jayathirthrao marked this pull request as draft August 20, 2025 05:24
@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 20, 2025
@jayathirthrao jayathirthrao marked this pull request as ready for review August 21, 2025 04:55
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 21, 2025
@jayathirthrao jayathirthrao requested a review from prrace August 21, 2025 05:04
int height = ir.getHeight(-1);
ImageTypeSpecifier specifier = ir.getRawImageType(-1);
} catch (IndexOutOfBoundsException e) {
if (Objects.equals(e.getMessage(), "imageIndex < 0")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit fragile checking the exception text, but I suppose it won't be changed unless this test changes too.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 21, 2025
@@ -391,6 +391,12 @@ private void checkTablesOnly() throws IOException {
tablesOnlyChecked = true;
}

private void checkNegativeImageIndex(int imageIndex) {
if (imageIndex < minIndex) {
throw new IndexOutOfBoundsException("imageIndex < " + minIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we irrespectively throw IOBE or check for seekForwardOnly before throwing the exception

* <p> The {@code seekForwardOnly} parameter controls whether
* the value returned by {@code getMinIndex} will be
* increased as each image (or thumbnail, or image metadata) is
* read. If {@code seekForwardOnly} is true, then a call to
* {@code read(index)} will throw an
* {@code IndexOutOfBoundsException} if {@code index < this.minIndex};
* otherwise, the value of
* {@code minIndex} will be set to {@code index}. If

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants