-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
base: master
Are you sure you want to change the base?
Conversation
…on-zero image index
👋 Welcome back jdv! A progress list of the required criteria for merging this PR into |
@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:
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
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 |
@jayathirthrao The following label will be automatically applied to this pull request:
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. |
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!"); | |||
} |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
int height = ir.getHeight(-1); | ||
ImageTypeSpecifier specifier = ir.getRawImageType(-1); | ||
} catch (IndexOutOfBoundsException e) { | ||
if (Objects.equals(e.getMessage(), "imageIndex < 0")) { |
There was a problem hiding this comment.
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.
@@ -391,6 +391,12 @@ private void checkTablesOnly() throws IOException { | |||
tablesOnlyChecked = true; | |||
} | |||
|
|||
private void checkNegativeImageIndex(int imageIndex) { | |||
if (imageIndex < minIndex) { | |||
throw new IndexOutOfBoundsException("imageIndex < " + minIndex); |
There was a problem hiding this comment.
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
jdk/src/java.desktop/share/classes/javax/imageio/ImageReader.java
Lines 228 to 235 in f423e1d
* <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 |
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
Issue
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