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

Mitsuru Kariya duke at openjdk.java.net
Sun Oct 24 07:55:01 UTC 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.

Mitsuru Kariya has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:

 - Merge branch 'master' into JDK-8153490
 - Follow the comment
 - Modify javadoc for consistency
 - Fix for length + offset > Integer.MAX_VALUE case
 - Add check: ensure length >= 0
 - 8153490:Cannot setBytes() if incoming buffer's length is bigger than 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.

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/4001/files
  - new: https://git.openjdk.java.net/jdk/pull/4001/files/c5d8056b..5ff182ce

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=4001&range=05
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=4001&range=04-05

  Stats: 836554 lines in 8575 files changed: 668559 ins; 128412 del; 39583 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


More information about the core-libs-dev mailing list