Skip to content

Commit d4e0ea7

Browse files
committed
Fix the implementation of StreamingXXHash32.asChecksum()
In the Checksum view, we only keep the last 28 bits of the hash instead of the 32 bits of the full hash. The result is that the 4 first bits are always set to 0 in LZ4Block*Stream. This commit: - fixes the Checksum view in StreamingXXHash32 - keeps the current behaviour in LZ4Block*Stream to avoid breaking existing data built with this library
1 parent a9c1b3a commit d4e0ea7

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/java/net/jpountz/lz4/LZ4BlockInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void refill() throws IOException {
257257
}
258258
checksum.reset();
259259
checksum.update(buffer, 0, originalLen);
260-
if ((int) checksum.getValue() != check) {
260+
if ((int) (checksum.getValue() & 0x0FFFFFFF) != check) {
261261
throw new IOException("Stream is corrupted");
262262
}
263263
o = 0;

src/java/net/jpountz/lz4/LZ4BlockOutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private void flushBufferedData() throws IOException {
206206
}
207207
checksum.reset();
208208
checksum.update(buffer, 0, o);
209-
final int check = (int) checksum.getValue();
209+
final int check = (int) (checksum.getValue() & 0x0FFFFFFF);
210210
int compressedLength = compressor.compress(buffer, 0, o, compressedBuffer, HEADER_LENGTH);
211211
final int compressMethod;
212212
if (compressedLength >= o) {

src/java/net/jpountz/xxhash/StreamingXXHash32.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final Checksum asChecksum() {
103103

104104
@Override
105105
public long getValue() {
106-
return StreamingXXHash32.this.getValue() & 0xFFFFFFFL;
106+
return StreamingXXHash32.this.getValue() & 0xFFFFFFFFL;
107107
}
108108

109109
@Override

0 commit comments

Comments
 (0)