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

JDK-8282144 RandomSupport.convertSeedBytesToLongs sign extension overwrites previous bytes #7614

Closed
wants to merge 1 commit into from

Conversation

JimLaskey
Copy link
Member

@JimLaskey JimLaskey commented Feb 24, 2022

Class: ./java.base/share/classes/jdk/internal/util/random/RandomSupport.java
Method: public static long[] convertSeedBytesToLongs(byte[] seed, int n, int z)

The method attempts to create an array of longs by consuming the input bytes most significant bit first. New bytes are appended to the existing long using the OR operator on the signed byte. Due to sign extension this will overwrite all the existing bits from 63 to 8 if the next byte is negative.


Progress

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

Issue

  • JDK-8282144: RandomSupport.convertSeedBytesToLongs sign extension overwrites previous bytes

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7614

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 24, 2022

👋 Welcome back jlaskey! 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 openjdk bot added the rfr Pull request is ready for review label Feb 24, 2022
@openjdk
Copy link

openjdk bot commented Feb 24, 2022

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Feb 24, 2022
@mlbridge
Copy link

mlbridge bot commented Feb 24, 2022

Webrevs


public class T8282144 {
public static void main(String[] args) {
RandomGenerator rng = RandomGeneratorFactory.of("L64X128MixRandom").create(42);
Copy link
Member

Choose a reason for hiding this comment

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

Does rng always produce the same sequence? If so, then perhaps the seed, 42, should be a random value that is printed.

Copy link
Member Author

Choose a reason for hiding this comment

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

42 was chosen because its is known to produce negative byte values, other random values might not.

Copy link
Member

Choose a reason for hiding this comment

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

OK


for (int k = 0; k < existing.length; k++) {
if (existing[k] != testing[k]) {
throw new RuntimeException("convertSeedBytesToLongs incorrect");
Copy link
Member

Choose a reason for hiding this comment

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

Should i, j, and k be included in the exception message?

Copy link
Member Author

@JimLaskey JimLaskey Feb 27, 2022

Choose a reason for hiding this comment

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

Correctness is binary - either it works or it doesn't. The values of i, j, k would not assist in isolating issues. Might add to confusion if displayed.

Copy link
Member

Choose a reason for hiding this comment

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

Understood.

@openjdk
Copy link

openjdk bot commented Mar 7, 2022

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

8282144: RandomSupport.convertSeedBytesToLongs sign extension overwrites previous bytes

Reviewed-by: bpb

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

  • 50eb915: 8282632: Cleanup unnecessary calls to Throwable.initCause() in java.security.jgss
  • ccad392: 8282657: Code cleanup: removing double semicolons at the end of lines
  • 5d5bf16: 8282567: Improve source-date handling in build system
  • 3996782: 8281093: Violating Attribute-Value Normalization in the XML specification 1.0
  • 2e298b8: 8272691: Fix HotSpot style guide terminology for "non-local variables"
  • 5953b22: 8257589: HotSpot Style Guide should link to rfc7282
  • 1faa5c8: 8282686: Add constructors taking a cause to SocketException
  • 7194097: 8252577: HotSpot Style Guide should link to One-True-Brace-Style description
  • ef266d7: 8278296: Generalize long range check transformation
  • f0995ab: 8280404: Unexpected exception thrown when CEN file entry comment length is not valid
  • ... and 102 more: https://git.openjdk.java.net/jdk/compare/f4486a190e38c57b7c10e6cff4622bd1b716a724...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 Mar 7, 2022
@JimLaskey
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 8, 2022

Going to push as commit 5fab27e.
Since your change was applied there have been 117 commits pushed to the master branch:

  • 65ca0a5: 8276333: jdk/jfr/event/oldobject/TestLargeRootSet.java failed "assert(!contains(edge->reference())) failed: invariant"
  • e607287: 8282728: Serial: Remove unused BlockOffsetArray::Action
  • 8b45dbd: 8282312: Minor corrections to evbroadcasti32x4 intrinsic on x86
  • 3f0684d: 8275775: Add jcmd VM.classes to print details of all classes
  • cde923d: 8282690: runtime/CommandLine/VMDeprecatedOptions.java fails after JDK-8281181
  • 50eb915: 8282632: Cleanup unnecessary calls to Throwable.initCause() in java.security.jgss
  • ccad392: 8282657: Code cleanup: removing double semicolons at the end of lines
  • 5d5bf16: 8282567: Improve source-date handling in build system
  • 3996782: 8281093: Violating Attribute-Value Normalization in the XML specification 1.0
  • 2e298b8: 8272691: Fix HotSpot style guide terminology for "non-local variables"
  • ... and 107 more: https://git.openjdk.java.net/jdk/compare/f4486a190e38c57b7c10e6cff4622bd1b716a724...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 8, 2022

@JimLaskey Pushed as commit 5fab27e.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
2 participants