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
Changes from 2 commits
8849de9
6a0cc1a
e434673
69fb2f4
c5d8056
5ff182c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you please create a CSR for me? |
||
* @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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though this addresses a typo, this will require a CSR |
||
* if {@code free} had previously been called on this object | ||
* @throws SQLException if there is an error accessing the <code>BLOB</code> | ||
* value from the database | ||
|
@@ -327,27 +326,27 @@ public int setBytes(long pos, byte[] bytes) | |
* <code>BLOB</code> value that this <code>Blob</code> object represents | ||
* and returns the number of bytes written. | ||
* Writing starts at position <code>pos</code> in the <code>BLOB</code> | ||
* value; <i>len</i> bytes from the given byte array are written. | ||
* value; {@code length} bytes from the given byte array are written. | ||
* | ||
* @param pos the position in the <code>BLOB</code> object 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. | ||
* @param bytes the array of bytes to be written to the <code>BLOB</code> | ||
* value | ||
* @param offset the offset in the <code>byte</code> array at which | ||
* to start reading the bytes. The first offset position is | ||
* @param offset the offset into the array {@code bytes} at which | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change all occurrences of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for my very slow response. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No problem at all. I was delayed in getting the CSR created and finalized.
|
||
* to start reading the bytes to be set. 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 | ||
* than the length of the array {@code bytes} | ||
* @param length the number of bytes to be written to the | ||
* <code>BLOB</code> value from the array of bytes <i>bytes</i>. | ||
* <code>BLOB</code> value from the array of bytes {@code bytes} | ||
* | ||
* @return the number of bytes written | ||
* @throws SerialException if there is an error accessing the | ||
* <code>BLOB</code> value; if an invalid position is set; if an | ||
* invalid offset value is set; if number of bytes to be written | ||
* is greater than the <code>SerialBlob</code> length; or the combined | ||
* values of the length and offset is greater than the Blob buffer; | ||
* invalid offset value is set; or the combined values of the | ||
* {@code length} and {@code offset} is greater than the length of | ||
* {@code bytes}; | ||
* if {@code free} had previously been called on this object | ||
* @throws SQLException if there is an error accessing the <code>BLOB</code> | ||
* value from the database. | ||
|
@@ -361,26 +360,34 @@ public int setBytes(long pos, byte[] bytes, int offset, int length) | |
throw new SerialException("Invalid offset in byte array set"); | ||
} | ||
|
||
if (pos < 1 || pos > this.length()) { | ||
throw new SerialException("Invalid position in BLOB object set"); | ||
if (length < 0) { | ||
throw new SerialException("Invalid arguments: length cannot be " | ||
+ "negative"); | ||
} | ||
|
||
if ((long)(length) > origLen) { | ||
throw new SerialException("Buffer is not sufficient to hold the value"); | ||
if (pos < 1 || pos > len + 1) { | ||
throw new SerialException("Invalid position in BLOB object set"); | ||
} | ||
|
||
if ((length + offset) > bytes.length) { | ||
throw new SerialException("Invalid OffSet. Cannot have combined offset " + | ||
"and length that is greater that the Blob buffer"); | ||
"and length that is greater than the length of bytes"); | ||
} | ||
|
||
if (pos - 1 + length > Integer.MAX_VALUE) { | ||
throw new SerialException("Invalid length. Cannot have combined pos " + | ||
"and length that is greater than Integer.MAX_VALUE"); | ||
} | ||
|
||
int i = 0; | ||
pos--; // correct to array indexing | ||
while ( i < length || (offset + i +1) < (bytes.length-offset) ) { | ||
this.buf[(int)pos + i] = bytes[offset + i ]; | ||
i++; | ||
if (pos + length > len) { | ||
len = pos + length; | ||
byte[] newbuf = new byte[(int)len]; | ||
System.arraycopy(buf, 0, newbuf, 0, (int)pos); | ||
buf = newbuf; | ||
} | ||
return i; | ||
System.arraycopy(bytes, offset, buf, (int)pos, length); | ||
return length; | ||
} | ||
|
||
/** | ||
|
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.
When updating the javadoc to use @code, please update all instances for consistency
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.
Sure.