Skip to content

Commit 86c6a40

Browse files
committed
Check ByteBuffer 32-bits limitations
1 parent 6fc8c74 commit 86c6a40

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/c_api/AbstractTF_Buffer.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static TF_Buffer newBufferFromString(Pointer proto) {
7272
}
7373

7474
/**
75-
* Returns a copy of the data in a Java array, or throws IndexOutOfBoundsException if too large.
75+
* @return a copy of the data in a Java array
76+
* @throws IndexOutOfBoundsException if too large.
7677
*/
7778
public byte[] copyData() {
7879
long length = ((TF_Buffer)this).length();
@@ -85,10 +86,15 @@ public byte[] copyData() {
8586
}
8687

8788
/**
88-
* Returns the data of this buffer as a {@link java.nio.ByteBuffer}
89+
* @return the data of this buffer as a {@link java.nio.ByteBuffer}
90+
* @throws IndexOutOfBoundsException if too large.
8991
*/
9092
public ByteBuffer dataAsByteBuffer() {
91-
return ((TF_Buffer)this).data().capacity(((TF_Buffer) this).length()).asByteBuffer();
93+
long length = ((TF_Buffer)this).length();
94+
if (length > Integer.MAX_VALUE) {
95+
throw new IndexOutOfBoundsException("TF_Buffer is too large to accessed via a ByteBuffer interface");
96+
}
97+
return ((TF_Buffer)this).data().capacity(length).asByteBuffer();
9298
}
9399

94100
/**

0 commit comments

Comments
 (0)