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

8153490: Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert. #4001

Closed
wants to merge 6 commits into from

Conversation

kariya-mitsuru
Copy link
Contributor

@kariya-mitsuru kariya-mitsuru commented May 12, 2021

Fix SerialBlob.setBytes(long pos, byte[] bytes, int offset, int length) in the following cases:

  1. pos - 1 + bytes.length - offset > this.length() && pos - 1 + length <= this.length()
    The original implementation throws ArrayIndexOutOfBoundsException but this case should end successfully.
    (test31)

  2. pos - 1 + length > this.length()
    The original implementation throws ArrayIndexOutOfBoundsException but this case should end successfully. *1
    (test32)

  3. pos == this.length() + 1
    The original implementation throws SerialException but this case should end successfully. *2
    (test33)

  4. length < 0
    The original implementation throws ArrayIndexOutOfBoundsException but this case should throw SerialException.
    (test34)

  5. offset + length > Integer.MAX_VALUE
    The original implementation throws ArrayIndexOutOfBoundsException (or OutOfMemoryError in most cases) but this case should throw SerialException.
    (test35)

Additionally, fix SerialClob.setString(long pos, String str, int offset, int length) in the following cases:

  1. offset > str.length()
    The original implementaion throws StringIndexOutOfBoundsException but this case should throw SerialException.
    (test39)

  2. pos - 1 + str.length() - offset > this.length() && pos - 1 + length <= this.length()
    The original implementation throws ArrayIndexOutOfBoundsException but this case should end successfully.
    (test32)

  3. pos - 1 + length > this.length()
    The original implementaion throws SerialException but this case should end successfully. *3
    (test40)

  4. pos == this.length() + 1
    The original implementaion throws SerialException but this case should end successfully. *4
    (test41)

  5. length < 0
    The original implementation throws StringIndexOutOfBoundsException but this case should throw SerialException.
    (test42)

  6. offset + length > Integer.MAX_VALUE
    The original implementation throws ArrayIndexOutOfBoundsException (or OutOfMemoryError in most cases) but this case should throw SerialException.
    (test43)

The javadoc has also been modified according to the above.

*1 The documentation of Blob.setBytes() says, "If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accommodate the extra bytes."

*2 The documentation of Blob.setBytes() says, "If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined."
So, it should work correctly when pos == length+1 of the BLOB value.

*3 The documentation of Clob.setString() says, "If the end of the Clob value is eached while writing the given string, then the length of the Clob value will be increased to accommodate the extra characters."

*4 The documentation of Clob.setString() says, "If the value specified for pos is greater than the length+1 of the CLOB value then the behavior is undefined."
So, it should work correctly when pos == length+1 of the CLOB value.


Progress

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

Issue

  • JDK-8153490: Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert.

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4001

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

Using diff file

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

…number of elements we want to insert.

Fix SerialBlob.setBytes(long pos, byte[] bytes, int offset, int length) in the
following cases:

1. pos - 1 + bytes.length - offset > this.length() && pos - 1 + length <= this.length()
   The original implementation throws ArrayIndexOutOfBoundsException but this case
   should end successfully.
   (test31)

2. pos - 1 + length > this.length()
   The original implementation throws ArrayIndexOutOfBoundsException but this case
   should end successfully. *1
   (test32)

3. pos == this.length() + 1
   The original implementation throws SerialException but this case should end
   successfully. *2
   (test33)

Additionally, fix SerialClob.setString(long pos, String str, int offset, int length)
in the following cases:

1. offset > str.length()
   The original implementaion throws StringIndexOutOfBoundsException but this case
   should throw SerialException.
   (test39)

2. pos - 1 + str.length() - offset > this.length() && pos - 1 + length <= this.length()
   The original implementation throws ArrayIndexOutOfBoundsException but this case
   should end successfully.
   (test32)

3. pos - 1 + length > this.length()
   The original implementaion throws SerialException but this case should end
   successfully. *3
   (test40)

4. pos == this.length() + 1
   The original implementaion throws SerialException but this case should end
   successfully. *4
   (test41)

The javadoc has also been modified according to the above.

*1 The documentation of Blob.setBytes() says, "If the end of the Blob value is
   reached while writing the array of bytes, then the length of the Blob value
   will be increased to accommodate the extra bytes."

*2 The documentation of Blob.setBytes() says, "If the value specified for pos
   is greater than the length+1 of the BLOB value then the behavior is
   undefined."
   So, it should work correctly when pos == length+1 of the BLOB value.

*3 The documentation of Clob.setString() says, "If the end of the Clob value is
   reached while writing the given string, then the length of the Clob value
   will be increased to accommodate the extra characters."

*4 The documentation of Clob.setString() says, "If the value specified for pos
   is greater than the length+1 of the CLOB value then the behavior is
   undefined."
   So, it should work correctly when pos == length+1 of the CLOB value.
@bridgekeeper
Copy link

bridgekeeper bot commented May 12, 2021

👋 Welcome back kariya-mitsuru! 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 May 12, 2021

@kariya-mitsuru 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 May 12, 2021
@kariya-mitsuru kariya-mitsuru changed the title 8153490:Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert. 8153490: Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert. May 12, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label May 12, 2021
@mlbridge
Copy link

mlbridge bot commented May 12, 2021

Webrevs

@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Mailing list message from Lance Andersen on core-libs-dev:

I won?t have time to look at this today, might not be until over the weekend.

On May 12, 2021, at 2:07 PM, Mitsuru Kariya <github.com+2217224+kariya-mitsuru at openjdk.java.net<mailto:github.com+2217224+kariya-mitsuru at openjdk.java.net>> wrote:

Fix `SerialBlob.setBytes(long pos, byte[] bytes, int offset, int length)` in the following cases:

1. `pos - 1 + bytes.length - offset > this.length() && pos - 1 + length <= this.length()`
The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully.
(test31)

2. `pos - 1 + length > this.length()`
The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully. *1
(test32)

3. `pos == this.length() + 1`
The original implementation throws `SerialException` but this case should end successfully. *2
(test33)

Additionally, fix `SerialClob.setString(long pos, String str, int offset, int length)` in the following cases:

1. `offset > str.length()`
The original implementaion throws `StringIndexOutOfBoundsException` but this case should throw `SerialException`.
(test39)

2. `pos - 1 + str.length() - offset > this.length() && pos - 1 + length <= this.length()`
The original implementation throws `ArrayIndexOutOfBoundsException` but this case should end successfully.
(test32)

3. `pos - 1 + length > this.length()`
The original implementaion throws `SerialException` but this case should end successfully. *3
(test40)

4. `pos == this.length() + 1`
The original implementaion throws `SerialException` but this case should end successfully. *4
(test41)

The javadoc has also been modified according to the above.

The items below should would change the spec change, require a CSR and should be looked at separately

*1 The documentation of `Blob.setBytes()` says, "If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accommodate the extra bytes."

*2 The documentation of `Blob.setBytes()` says, "If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined."
So, it should work correctly when pos == length+1 of the BLOB value.

*3 The documentation of `Clob.setString()` says, "If the end of the Clob value is eached while writing the given string, then the length of the Clob value will be increased to accommodate the extra characters."

*4 The documentation of `Clob.setString()` says, "If the value specified for pos is greater than the length+1 of the CLOB value then the behavior is undefined."
So, it should work correctly when pos == length+1 of the CLOB value.

-------------

Commit messages:
- 8153490:Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert.

Changes: https://git.openjdk.java.net/jdk/pull/4001/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4001&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8153490
Stats: 179 lines in 4 files changed: 122 ins; 17 del; 40 mod
Patch: https://git.openjdk.java.net/jdk/pull/4001.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/4001/head:pull/4001

PR: https://git.openjdk.java.net/jdk/pull/4001

[cid:E1C4E2F0-ECD0-4C9D-ADB4-B16CA7BCB7FC at home]

Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com<mailto:Lance.Andersen at oracle.com>

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Overall the changes look reasonable. As mentioned in the comments, a CSR will be required due to some of the wordsmithing cleanup

@@ -305,13 +305,12 @@ public long position(Blob pattern, long start)
* @param pos the position in the SQL <code>BLOB</code> value at which
* to start writing. The first position is <code>1</code>;
* must not be less than <code>1</code> nor greater than
* the length of this <code>SerialBlob</code> object.
* the length+1 of this {@code SerialBlob} object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes such as this require a CSR. I think I have convinced myself that it is OK to move forward with the CSR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you please create a CSR for me?
Or should I register a CSR at https://bugreport.java.com/bugreport/ ?

@@ -305,13 +305,12 @@ public long position(Blob pattern, long start)
* @param pos the position in the SQL <code>BLOB</code> value at which
* to start writing. The first position is <code>1</code>;
Copy link
Contributor

Choose a reason for hiding this comment

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

When updating the javadoc to use @code, please update all instances for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

* @param bytes the array of bytes to be written to the <code>BLOB</code>
* value that this <code>Blob</code> object represents
* @return the number of bytes written
* @throws SerialException if there is an error accessing the
* <code>BLOB</code> value; or if an invalid position is set; if an
* invalid offset value is set;
* {@code BLOB} value; or if an invalid position is set;
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though this addresses a typo, this will require a CSR

@LanceAndersen
Copy link
Contributor

/csr

@LanceAndersen
Copy link
Contributor

I have run the JCK tests in addition to to the JTREG Tess to validate there are no additional failures due to these changes

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label May 18, 2021
@openjdk
Copy link

openjdk bot commented May 18, 2021

@LanceAndersen has indicated that a compatibility and specification (CSR) request is needed for this pull request.
@kariya-mitsuru please create a CSR request for issue JDK-8153490. This pull request cannot be integrated until the CSR request is approved.

@kariya-mitsuru
Copy link
Contributor Author

I have run the JCK tests in addition to to the JTREG Tess to validate there are no additional failures due to these changes

Thanks a lot!

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 21, 2021

@kariya-mitsuru This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 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!

@LanceAndersen
Copy link
Contributor

I hope to get to the CSR this week. Sorry for the delay

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 19, 2021

@kariya-mitsuru This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 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!

@LanceAndersen
Copy link
Contributor

This is waiting on the CSR which I have to pull together so please keep this open

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 16, 2021

@kariya-mitsuru This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 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!

@LanceAndersen
Copy link
Contributor

In process

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 13, 2021

@kariya-mitsuru This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 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!

* to start reading the bytes. The first offset position is
* <code>0</code>; must not be less than <code>0</code> nor greater
* than the length of the <code>byte</code> array
* @param offset the offset into the array {@code bytes} at which
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change all occurrences of {@code bytes} to {@code byte}s as this was caught as part of the CSR review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for my very slow response.
These {@code bytes} point to the bytes argument, but should I change it to {@code byte}s?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for my very slow response.

No problem at all. I was delayed in getting the CSR created and finalized.

These {@code bytes} point to the bytes argument, but should I change it to {@code byte}s?
Yes please make that minor change. Thank you

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Sep 21, 2021
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2021

@kariya-mitsuru This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Oct 13, 2021
@kariya-mitsuru
Copy link
Contributor Author

/open

@openjdk openjdk bot reopened this Oct 14, 2021
@openjdk
Copy link

openjdk bot commented Oct 14, 2021

@kariya-mitsuru This pull request is now open

@openjdk
Copy link

openjdk bot commented Oct 15, 2021

@kariya-mitsuru 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:

8153490: Cannot setBytes() if incoming buffer's length is bigger than number of elements we want to insert.

Reviewed-by: lancea

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

  • 9a3e954: 8274879: Replace uses of StringBuffer with StringBuilder within java.base classes
  • e6fa5fa: 8276063: ProblemList gtest dll_address_to_function_and_library_name on macosx-generic
  • 809488b: 8276046: codestrings.validate_vm gtest fails on ppc64, s390
  • 93be099: 4718400: Many quantities are held as signed that should be unsigned
  • 168081e: 8270490: Charset.forName() taking fallback default value
  • a292733: 8275975: Remove dead code in ciInstanceKlass
  • 4060602: 8275800: Redefinition leaks MethodData::_extra_data_lock
  • 485d658: 8275851: Deproblemlist open/test/jdk/javax/swing/JComponent/6683775/bug6683775.java
  • b3f45f8: 8275689: [TESTBUG] Use color tolerance only for XRender in BlitRotateClippedArea test
  • 6c05cc9: 8275863: Use encodeASCII for ASCII-compatible DoubleByte encodings
  • ... and 36 more: https://git.openjdk.java.net/jdk/compare/5bbe4cae8746765d2ce965b06fd1e5cf512326ae...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@LanceAndersen) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 15, 2021
@kariya-mitsuru
Copy link
Contributor Author

The pre-submit test seems to have failed because the compiler was not found in some environments.
Should I take any action?
Or should I issue the /integrate pull request command?

@LanceAndersen
Copy link
Contributor

The pre-submit test seems to have failed because the compiler was not found in some environments.
Should I take any action?
Or should I issue the /integrate pull request command?

You should be OK. Just as an extra sanity check, I will run those tiers internally tomorrow so please stay tuned

@LanceAndersen
Copy link
Contributor

Any chance you can sync up your workspace with master? I am getting errors when I fetch and try to run our internal tests.

@LanceAndersen
Copy link
Contributor

Mach5 tiers 1-3 are clean so you should be OK to integrate your fix

@kariya-mitsuru
Copy link
Contributor Author

Thanks a lot!

@kariya-mitsuru
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 27, 2021
@openjdk
Copy link

openjdk bot commented Oct 27, 2021

@kariya-mitsuru
Your change (at version 5ff182c) is now ready to be sponsored by a Committer.

@LanceAndersen
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 28, 2021

Going to push as commit 63b9f8c.
Since your change was applied there have been 59 commits pushed to the master branch:

  • cb989cf: 8275052: AArch64: Severe AES/GCM slowdown on MacOS for short blocks
  • c92f230: 8276110: Problemlist javax/swing/JMenu/4515762/bug4515762.java for macos12
  • 309acbf: 8275703: System.loadLibrary fails on Big Sur for libraries hidden from filesystem
  • abe52ae: 8275518: accessibility issue in Inet6Address docs
  • 85d8cd8: 8276100: Remove G1SegmentedArray constructor name parameter
  • a343fa8: 8275865: Print deoptimization statistics in product builds
  • bec977c: 8275917: Some locks shouldn't allow_vm_block
  • 7c996d5: 8269401: Merge "Exceptions" and "Errors" into "Exception Classes"
  • d88b89f: 8276067: ZGC: Remove unused function alloc_high_address_at_most()
  • 593401f: 8276042: Remove unused local variables in java.naming
  • ... and 49 more: https://git.openjdk.java.net/jdk/compare/5bbe4cae8746765d2ce965b06fd1e5cf512326ae...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Oct 28, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 28, 2021
@openjdk
Copy link

openjdk bot commented Oct 28, 2021

@LanceAndersen @kariya-mitsuru Pushed as commit 63b9f8c.

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

@kariya-mitsuru
Copy link
Contributor Author

Thank you for your cooperation!

@kariya-mitsuru kariya-mitsuru deleted the JDK-8153490 branch November 15, 2021 04:30
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