Skip to content

Commit

Permalink
Fix the implementation of StreamingXXHash32.asChecksum()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trazfr committed Aug 25, 2021
1 parent a9c1b3a commit d4e0ea7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/java/net/jpountz/lz4/LZ4BlockInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void refill() throws IOException {
}
checksum.reset();
checksum.update(buffer, 0, originalLen);
if ((int) checksum.getValue() != check) {
if ((int) (checksum.getValue() & 0x0FFFFFFF) != check) {
throw new IOException("Stream is corrupted");
}
o = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/java/net/jpountz/lz4/LZ4BlockOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void flushBufferedData() throws IOException {
}
checksum.reset();
checksum.update(buffer, 0, o);
final int check = (int) checksum.getValue();
final int check = (int) (checksum.getValue() & 0x0FFFFFFF);
int compressedLength = compressor.compress(buffer, 0, o, compressedBuffer, HEADER_LENGTH);
final int compressMethod;
if (compressedLength >= o) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/net/jpountz/xxhash/StreamingXXHash32.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final Checksum asChecksum() {

@Override
public long getValue() {
return StreamingXXHash32.this.getValue() & 0xFFFFFFFL;
return StreamingXXHash32.this.getValue() & 0xFFFFFFFFL;
}

@Override
Expand Down

0 comments on commit d4e0ea7

Please sign in to comment.