Skip to content

Commit

Permalink
lz4stream/block: compute block checksum on the block not its source.
Browse files Browse the repository at this point in the history
Fixes #223.
  • Loading branch information
pierrec committed Dec 12, 2024
1 parent 294e765 commit fdaa7e2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/lz4stream/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (b *FrameDataBlock) Compress(f *Frame, src []byte, level lz4block.Compressi
b.src = src // keep track of the source for content checksum

if f.Descriptor.Flags.BlockChecksum() {
b.Checksum = xxh32.ChecksumZero(src)
b.Checksum = xxh32.ChecksumZero(b.Data)
}
return b
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func (b *FrameDataBlock) Uncompress(f *Frame, dst, dict []byte, sum bool) ([]byt
dst = dst[:n]
}
if f.Descriptor.Flags.BlockChecksum() {
if c := xxh32.ChecksumZero(dst); c != b.Checksum {
if c := xxh32.ChecksumZero(b.data); c != b.Checksum {
err := fmt.Errorf("%w: got %x; expected %x", lz4errors.ErrInvalidBlockChecksum, c, b.Checksum)
return nil, err
}
Expand Down

0 comments on commit fdaa7e2

Please sign in to comment.