From fdaa7e2eae2400f761d8503ca047b46d2ab67507 Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Thu, 12 Dec 2024 17:53:43 +0100 Subject: [PATCH] lz4stream/block: compute block checksum on the block not its source. Fixes #223. --- internal/lz4stream/block.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/lz4stream/block.go b/internal/lz4stream/block.go index e9646546..04aaca84 100644 --- a/internal/lz4stream/block.go +++ b/internal/lz4stream/block.go @@ -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 } @@ -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 }