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

JNU_GetStringPlatformChars may write to String's internal memory array

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • 17, 20, 21
    • core-libs
    • b26
    • Not verified

      When calling `JNU_GetStringPlatformChars` with UTF8 strings, the `getStringUTF8` function retrieves the internal String value array and copies its contents using `GetPrimitiveArrayCritical` and `ReleasePrimitiveArrayCritical`.

      Upon releasing the memory, the JNI_ABORT flag is not specified. If `GetPrimitiveArrayCritical` returns a copy of the array, then the call to `ReleasePrimitiveArrayCritical` copies the contents back.

      Strings in Java are considered immutable, and I think their memory should never be written to (even if the contents aren't changed). In GraalVM they may be stored in a read-only memory section making this behaviour cause a segfault. Using `JNI_ABORT` also improves the performance of the application when a copy is returned.

      I will submit a patch to add the JNI_ABORT flag to both calls of `ReleasePrimitiveArrayCritical`.

            rhorn Rudi Horn
            rhorn Rudi Horn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: