Uploaded image for project: 'ORC'
  1. ORC
  2. ORC-1034

The search byte array algorithm is incorrectly implemented in FileDump.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.0, 1.6.11
    • 1.7.1, 1.6.12
    • Java, tools
    • None

    Description

        private static int indexOf(final byte[] data, final byte[] pattern, final int index) {
          if (data == null || data.length == 0 || pattern == null || pattern.length == 0 ||
              index > data.length || index < 0) {
            return -1;
          }
      
          int j = 0;
          for (int i = index; i < data.length; i++) {
            if (pattern[j] == data[i]) {
              j++;
            } else {
              j = 0;
            }
      
            if (j == pattern.length) {
              return i - pattern.length + 1;
            }
          }
      
          return -1;
        }
      

      This matching algorithm is wrong when i does not backtrack after a failed match in the middle. As a simple example data = OOORC, pattern= ORC, index = 1, this algorithm will return -1.

      Attachments

        Issue Links

          Activity

            People

              Guiyankuang Yiqun Zhang
              Guiyankuang Yiqun Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: