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

AArch64: String.indexOf may incorrectly handle empty strings.

    Details

    • Subcomponent:
    • Resolved In Build:
      b13
    • CPU:
      aarch64
    • OS:
      linux

      Backports

        Description

        On AArch64, the String.indexOf() may produce incorrect results for empty
        strings due to absence of the argument length check in
        MacroAssembler::string_indexof_char().

        Following test demonstrates the problem:

        public class Test1 {
          public static void main(String ... str) {

            System.out.println("Begin");

            for (int i = 0 ; i < 100000; i ++) {
              String emptyString = "";
              for(int c=0; c<0xFFFF; c++) {
                int dot = emptyString.indexOf((char)c, -1);
                if (dot != -1) {
                  System.out.println("indexOf returned index " + dot);
                }
              }
            }

            System.out.println("End");
          }
        }

        Run:
        java -XX:-CompactStrings Test1


        Suggested fix:

        diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
        b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
        --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
        +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
        @@ -4860,6 +4860,8 @@
           Register ch1 = rscratch1;
           Register result_tmp = rscratch2;
         
        + cbz(cnt1, NOMATCH);
        +
           cmp(cnt1, (u1)4);
           br(LT, DO1_SHORT);

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bae Andrew Brygin
                  Reporter:
                  bae Andrew Brygin
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: