Skip to content

Commit

Permalink
zstd: Fix ignored crc (#580)
Browse files Browse the repository at this point in the history
When `IgnoreChecksum(true)` was used, single threaded decodes would not consume CRC.

Bonus: Remove crc build tag for fuzzing.
  • Loading branch information
klauspost committed May 6, 2022
1 parent f31f904 commit 50ba006
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
14 changes: 10 additions & 4 deletions zstd/decoder.go
Expand Up @@ -451,7 +451,7 @@ func (d *Decoder) nextBlock(blocking bool) (ok bool) {
got := d.current.crc.Sum64()
var tmp [4]byte
binary.LittleEndian.PutUint32(tmp[:], uint32(got))
if !d.o.ignoreChecksum && !bytes.Equal(tmp[:], next.d.checkCRC) && !ignoreCRC {
if !d.o.ignoreChecksum && !bytes.Equal(tmp[:], next.d.checkCRC) {
if debugDecoder {
println("CRC Check Failed:", tmp[:], " (got) !=", next.d.checkCRC, "(on stream)")
}
Expand Down Expand Up @@ -534,10 +534,16 @@ func (d *Decoder) nextBlockSync() (ok bool) {
}

// Update/Check CRC
if !d.o.ignoreChecksum && d.frame.HasCheckSum {
d.frame.crc.Write(d.current.b)
if d.frame.HasCheckSum {
if !d.o.ignoreChecksum {
d.frame.crc.Write(d.current.b)
}
if d.current.d.Last {
d.current.err = d.frame.checkCRC()
if !d.o.ignoreChecksum {
d.current.err = d.frame.checkCRC()
} else {
d.current.err = d.frame.consumeCRC()
}
if d.current.err != nil {
println("CRC error:", d.current.err)
return false
Expand Down
2 changes: 1 addition & 1 deletion zstd/framedec.go
Expand Up @@ -310,7 +310,7 @@ func (d *frameDec) checkCRC() error {
tmp[2] = byte(got >> 16)
tmp[3] = byte(got >> 24)

if !bytes.Equal(tmp[:], want) && !ignoreCRC {
if !bytes.Equal(tmp[:], want) {
if debugDecoder {
println("CRC Check Failed:", tmp[:], "!=", want)
}
Expand Down
11 changes: 0 additions & 11 deletions zstd/fuzz.go

This file was deleted.

11 changes: 0 additions & 11 deletions zstd/fuzz_none.go

This file was deleted.

0 comments on commit 50ba006

Please sign in to comment.