Uploaded image for project: 'Commons Codec'
  1. Commons Codec
  2. CODEC-269

Allow repeat calls to IncrementalHash32.end() to generate the same value.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 1.13
    • 1.14
    • None

    Description

      The MurmurHash3.IncrementalHash32 end() method alters the current state of the running hash. Thus if called twice it returns different numbers.

      This can be fixed using:

      public final int end() {
          // Allow calling end() again after adding no data to return the same result.
          int result = hash;
          // ************
          // Note: This fails to apply masking using 0xff to the 3 remaining bytes.
          // ************
          int k1 = 0;
          switch (unprocessedLength) {
          case 3:
              k1 ^= unprocessed[2] << 16;
          case 2:
              k1 ^= unprocessed[1] << 8;
          case 1:
              k1 ^= unprocessed[0];
      
              // mix functions
              k1 *= C1_32;
              k1 = Integer.rotateLeft(k1, R1_32);
              k1 *= C2_32;
              result ^= k1;
          }
      
          // finalization
          result ^= totalLen;
          return fmix32(result);
      }
      

      Attachments

        Activity

          People

            aherbert Alex Herbert
            aherbert Alex Herbert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: