Skip to content

Commit

Permalink
Disalow writes for C Java ABI imported buffers. This should prevent A…
Browse files Browse the repository at this point in the history
…rrowBuf from failing by writerIndex >= readerIndex check
  • Loading branch information
zhztheplayer committed May 17, 2022
1 parent eb68779 commit 6d25fe3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion java/c/src/main/java/org/apache/arrow/c/ArrayImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ private List<ArrowBuf> importBuffers(ArrowArray.Snapshot snapshot) {
if (bufferPtr != NULL) {
// TODO(roee88): an API for getting the size for each buffer is not yet
// available
buffer = new ArrowBuf(referenceManager, null, Integer.MAX_VALUE, bufferPtr);
int length = Integer.MAX_VALUE;
buffer = new ArrowBuf(referenceManager, null, length, bufferPtr);
buffer.writerIndex(length); // disallow writes
}
result.add(buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public ByteOrder order() {
*/
public long readableBytes() {
Preconditions.checkState(writerIndex >= readerIndex,
"Writer index cannot be less than reader index");
String.format("Writer index cannot be less than reader index: writer index: %d, reader index: %d",
writerIndex, readerIndex));
return writerIndex - readerIndex;
}

Expand Down Expand Up @@ -1152,6 +1153,9 @@ public ArrowBuf readerIndex(long readerIndex) {
* @return this ArrowBuf
*/
public ArrowBuf writerIndex(long writerIndex) {
if (writerIndex < 0) {
throw new RuntimeException("Negative writer index specified: " + writerIndex);
}
this.writerIndex = writerIndex;
return this;
}
Expand Down

0 comments on commit 6d25fe3

Please sign in to comment.