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

Add bound check in indexed memory access var handle

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • 19
    • 19
    • core-libs
    • None

      Consider the following memory access var handle creation:

      MemoryLayout layout = MemoryLayout.sequenceLayout(5, JAVA_INT);
      VarHandle VH = layout.varHandle(PathElement.sequenceLayout());

      And consider the following access expression:

      VH.get(segment, 10);

      Now, clearly, the index provided by the client (10) is outside the bound of the sequence layout used to construct the var handle. Currently the API does not report this as a direct error. Instead it allows access, which then will succeed or fail depending on the segment size. If the above expression is used to dereference a portion of a bigger segment, not detecting the out-of-bounds access might result in corrupting unrelated parts of the memory segment (think about struct access, where setting a field accidentally sets a different field).

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

              Created:
              Updated:
              Resolved: