Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8288534

Out of bound errors for memory segment access mentions wrong values

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2
    • 19
    • 19
    • core-libs
    • None

    Backports

      Description

        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.

        Attachments

          Issue Links

            Activity

              People

                mcimadamore Maurizio Cimadamore
                mcimadamore Maurizio Cimadamore
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: