Skip to content

Commit d6b18a0

Browse files
committed
Fix reading NULL byte from CByteArrayWrapper
1 parent 8f97899 commit d6b18a0

File tree

1 file changed

+11
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common

1 file changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CArrayWrappers.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,24 @@ boolean hasBufferElements() {
289289
@ExportMessage
290290
@ExportMessage(name = "getArraySize")
291291
long getBufferSize() {
292-
return getByteArray().length;
292+
return getByteArray().length + 1;
293293
}
294294

295295
@ExportMessage
296296
byte readBufferByte(long byteOffset) throws InvalidBufferOffsetException {
297+
byte[] bytes = getByteArray();
298+
/*
299+
* FIXME we only allow reading the NULL byte when reading by bytes, we should also allow
300+
* that when reading ints etc.
301+
*/
302+
if (byteOffset == bytes.length) {
303+
return 0;
304+
}
297305
try {
298-
return getByteArray()[(int) byteOffset];
306+
return bytes[(int) byteOffset];
299307
} catch (ArrayIndexOutOfBoundsException e) {
300308
CompilerDirectives.transferToInterpreterAndInvalidate();
301-
throw InvalidBufferOffsetException.create(byteOffset, getByteArray().length);
309+
throw InvalidBufferOffsetException.create(byteOffset, bytes.length);
302310
}
303311
}
304312

0 commit comments

Comments
 (0)