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

SegmentAllocator::allocateUtf8String(String str) should be clarified for strings containing \0

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • None
    • 19
    • core-libs

    Backports

      Description

        * Converts a Java string into a UTF-8 encoded, null-terminated C string, storing the result into a memory segment.
        String s1 = String.valueOf("123”);
        String s2 = new String(new char[]{0, 0, 0});
        seg1 = session.allocateUtf8String(s1);
        seg2 = session.allocateUtf8String(s2);
        seg1.byteSize() == seg2.byteSize() == 4

        From C point of view seg2 == “\0\0\0\0” isn’t C string it’s a string literal.A null-terminated byte string - is a sequence of zero or more characters followed by a byte with value zero

        Also, potentially, it is place to get loss of data integrity

        String s1 = new String(new char[]{'a', 'b', 0, 'd'});
        segment = session.allocateUtf8String(s1);
        String s2 = segment.getUtf8String(0);
        s1 != s2

        Attachments

          Issue Links

            Activity

              People

                jvernee Jorn Vernee
                lkuskov Leonid Kuskov
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: