Skip to content

Commit

Permalink
zstd: Fix ignored crc
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 8e3eb92
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
20 changes: 12 additions & 8 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,13 +534,17 @@ 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.current.d.Last {
d.current.err = d.frame.checkCRC()
if d.current.err != nil {
println("CRC error:", d.current.err)
return false
if d.frame.HasCheckSum {
if !d.o.ignoreChecksum {
d.frame.consumeCRC()
} else {
d.frame.crc.Write(d.current.b)
if d.current.d.Last {
d.current.err = d.frame.checkCRC()
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 8e3eb92

Please sign in to comment.