Skip to content
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

8264666: Change implementation of safeAdd/safeMult in the LCMSImageLayout class #3333

Closed
wants to merge 6 commits into from

Conversation

mrserb
Copy link
Member

@mrserb mrserb commented Apr 2, 2021

Description of the new version of the fix:
While I have worked on this change and tried to consider the comments, I have found that the usages of the "safeAdd/safeMult" in the LCMSImageLayout class are incorrect. Both methods are based on the "Math" versions but throw a different exception. The problem is that its implementation may accept the negative values during intermediate calculation, see the old implementation of "verify" method:

  1. We check the "offset" value: 0 <= offset < dataArrayLength
  2. We do some intermediate calculations that "accept" negative values
  3. We check the final "off" value: 0 <= offset < dataArrayLength

I wondered is it possible to provide some data that using wrong/negative data at step2 may result in the correct check at step3. I spent some time and was able to reproduce the problem with the attached test case. Note that the test is a little bit cryptic since it is not possible to reproduce it by input image data.

Note: I have removed all cleanup from the fix, to make it simpler.

<======>
Description of the old version of the fix:

  • The hand-crafted methods for addition and multiplication are replaced by the "Math" versions.
  • Cleanup: the usage of do/while(false) is removed

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8264666: Change implementation of safeAdd/safeMult in the LCMSImageLayout class

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3333/head:pull/3333
$ git checkout pull/3333

Update a local copy of the PR:
$ git checkout pull/3333
$ git pull https://git.openjdk.java.net/jdk pull/3333/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3333

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3333.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 2, 2021

👋 Welcome back serb! 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 Apr 2, 2021

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

  • 2d

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.

@openjdk openjdk bot added the 2d client-libs-dev@openjdk.org label Apr 2, 2021
@mrserb
Copy link
Member Author

mrserb commented Apr 2, 2021

The nice PR number: 3333!

if (l.nextRowOffset == l.width * 4 * intRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
Copy link
Member Author

Choose a reason for hiding this comment

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

Any idea why the "do/while(false)" was used here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can only guess it was just style ..

Copy link
Member

Choose a reason for hiding this comment

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

Probably it is just a way to highlight and improve readability of a block of code, but simply {} would be enough in this case.

@mrserb mrserb marked this pull request as ready for review April 7, 2021 19:48
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 7, 2021
@mlbridge
Copy link

mlbridge bot commented Apr 7, 2021

Webrevs

@prrace
Copy link
Contributor

prrace commented Apr 7, 2021

I don't understand the exception handling here. multiplyExact and addExact will throw a runtime exception - ArithmeticException. And I don't see where it is caught. The change for ImageLayoutException to extend ArithmeticException doesn't seem like it can help here. Where is the ArithmeticException being turned into ImageLayoutException ?

@mrserb
Copy link
Member Author

mrserb commented Apr 7, 2021

I don't understand the exception handling here. multiplyExact and addExact will throw a runtime exception - ArithmeticException. And I don't see where it is caught. The change for ImageLayoutException to extend ArithmeticException doesn't seem like it can help here. Where is the ArithmeticException being turned into ImageLayoutException ?

O_o for some reason... missed that.

@mrserb mrserb marked this pull request as draft April 8, 2021 01:17
@openjdk openjdk bot removed the rfr Pull request is ready for review label Apr 8, 2021
@bridgekeeper
Copy link

bridgekeeper bot commented May 6, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

4 similar comments
@bridgekeeper
Copy link

bridgekeeper bot commented Jun 3, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 5, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 3, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 31, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Sep 10, 2021
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 28, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

5 similar comments
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 27, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 26, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 29, 2021

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 27, 2022

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 24, 2022

@mrserb This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@mrserb
Copy link
Member Author

mrserb commented Apr 6, 2022

I think the usage of these methods in this class is wrong. Both allow negative values which should not be accepted.

@mrserb mrserb changed the title 8264666: Reuse Math.multiplyExact/addExact in the LCMSImageLayout class 8264666: Change implementation of safeAdd/safeMult in the LCMSImageLayout class Apr 22, 2022
@mrserb mrserb marked this pull request as ready for review April 22, 2022 08:16
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 22, 2022
@mrserb
Copy link
Member Author

mrserb commented Apr 22, 2022

The fix is reworked based on the new facts about that methods.

if (l.nextRowOffset == l.width * 4 * intRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can only guess it was just style ..

@openjdk
Copy link

openjdk bot commented Apr 27, 2022

@mrserb 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:

8264666: Change implementation of safeAdd/safeMult in the LCMSImageLayout class

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 64 new commits pushed to the master branch:

  • 8a16842: 8176501: Method Shape.getBounds2D() incorrectly includes Bezier control points in bounding box
  • 05dac5a: 8280468: Crashes in getConfigColormap, getConfigVisualId, XVisualIDFromVisual on Linux
  • 6db2e16: 8284077: Create an automated test for JDK-4170173
  • a0b984a: 8282933: Create a test for JDK-4529616
  • 716a80a: 8283179: SA tests fail with "ERROR: catch_mach_exception_raise: Message doesn't denote a Unix soft signal."
  • 6c79671: 8285633: Take better advantage of generic MethodType cache
  • 5b42747: 8285736: JDK-8236128 causes validate-source failures
  • 6ce4e75: 8284726: Print active locale settings in hs_err reports and in VM.info
  • b675c59: 8236128: Allow jpackage create installers for services
  • ef27081: 8285671: java/nio/channels/etc/PrintSupportedOptions.java and java/nio/channels/DatagramChannel/AfterDisconnect.java are failing
  • ... and 54 more: https://git.openjdk.java.net/jdk/compare/d84b9c54893dd33686d49755fca7a4b7f6a681c4...master

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 ready Pull request is ready to be integrated label Apr 27, 2022
@mrserb
Copy link
Member Author

mrserb commented Apr 29, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Apr 29, 2022

Going to push as commit 40f19c0.
Since your change was applied there have been 92 commits pushed to the master branch:

  • 1e28fcb: 8155701: The compiler fails with an AssertionError: typeSig ERROR
  • 99388ef: 8283624: Create an automated regression test for RFE-4390885
  • 94b533a: 8285699: riscv: Provide information when hitting a HaltNode
  • e2e943a: 8285688: Add links to JEPs and JSRs to SourceVersion
  • 80cf59f: 8285610: TreeInfo.pathFor and its uses appear to be dead code
  • 21b62fe: 8195589: T6587786.java failed after JDK-8189997
  • 8190217: 8285496: DocLint does not check for missing @param tags for type parameters on classes and interfaces
  • 64d98ba: 8285094: Test java/awt/Frame/InvisibleOwner/InvisibleOwner.java failing on Linux
  • 573eace: 8285504: Minor cleanup could be done in javax.net
  • bba456a: 8285676: Add missing @param tags for type parameters on classes and interfaces
  • ... and 82 more: https://git.openjdk.java.net/jdk/compare/d84b9c54893dd33686d49755fca7a4b7f6a681c4...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 29, 2022
@openjdk openjdk bot closed this Apr 29, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 29, 2022
@openjdk
Copy link

openjdk bot commented Apr 29, 2022

@mrserb Pushed as commit 40f19c0.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@mrserb mrserb deleted the LCMSImageLayout branch May 16, 2022 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d client-libs-dev@openjdk.org client client-libs-dev@openjdk.org integrated Pull request has been integrated
3 participants