-
Bug
-
Resolution: Fixed
-
P2
-
19
-
None
-
b28
-
Fix failed
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8288677 | 20 | Maurizio Cimadamore | P2 | Resolved | Fixed | b03 |
Consider this program:
public class TestOOB {
public static void main(String[] args) {
var segment = MemorySegment.allocateNative(10, MemorySession.global());
segment.getAtIndex(ValueLayout.JAVA_INT, 2);
}
}
There is an out of bound access here, as we are accessing segment at offset 8 with access length 4 (an int) - but the segment is only 10 bytes long.
The exception coming out of the API is as follows:
java.lang.IndexOutOfBoundsException: Index 8 out of bounds for length 7
Note that, while the offset is correct, the access length is misreported. This is due to the fact that the implementation subtracts quantities, to avoid overflow.
In some cases (access length > segment size) one can even observe negative values in the message.
public class TestOOB {
public static void main(String[] args) {
var segment = MemorySegment.allocateNative(10, MemorySession.global());
segment.getAtIndex(ValueLayout.JAVA_INT, 2);
}
}
There is an out of bound access here, as we are accessing segment at offset 8 with access length 4 (an int) - but the segment is only 10 bytes long.
The exception coming out of the API is as follows:
java.lang.IndexOutOfBoundsException: Index 8 out of bounds for length 7
Note that, while the offset is correct, the access length is misreported. This is due to the fact that the implementation subtracts quantities, to avoid overflow.
In some cases (access length > segment size) one can even observe negative values in the message.
- backported by
-
JDK-8288677 Out of bound errors for memory segment access mentions wrong values
- Resolved
- relates to
-
JDK-8290820 java/foreign/TestSegments.java failed unexpectedly
- Closed