Skip to content

Commit 984dea7

Browse files
authored
Fix offset handling in Murmur3Hasher (#133193)
1 parent e6c2814 commit 984dea7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/changelog/133193.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 133193
2+
summary: Fix offset handling in Murmur3Hasher
3+
area: Infra/Core
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/common/hash/Murmur3Hasher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void update(byte[] inputBytes, int offset, int length) {
7575
System.arraycopy(inputBytes, offset + numBytesToHash, remainder, 0, remainderLength);
7676
}
7777
} else {
78-
System.arraycopy(inputBytes, 0, remainder, remainderLength, length);
78+
System.arraycopy(inputBytes, offset, remainder, remainderLength, length);
7979
remainderLength += length;
8080
}
8181
}

server/src/test/java/org/elasticsearch/common/hashing/Murmur3HasherTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ private static void assertHash(long lower, long upper, String inputString, long
3535
expected.h2 = upper;
3636

3737
byte[] bytes = inputString.getBytes(StandardCharsets.UTF_8);
38+
int padding = randomInt(8);
39+
int offset = randomInt(padding);
40+
byte[] paddedBytes = new byte[bytes.length + padding];
41+
System.arraycopy(bytes, 0, paddedBytes, offset, bytes.length);
3842
Murmur3Hasher mh = new Murmur3Hasher(seed);
39-
mh.update(bytes);
43+
mh.update(paddedBytes, offset, bytes.length);
4044
MurmurHash3.Hash128 actual = mh.digestHash();
4145
assertHash(expected, actual);
4246
}

0 commit comments

Comments
 (0)