Skip to content

Commit

Permalink
internal/zstd: fix regeneratedSize too small to cause panic
Browse files Browse the repository at this point in the history
  • Loading branch information
aimuz committed Nov 6, 2023
1 parent 4cd201b commit c76e909
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/internal/zstd/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var badStrings = []string{
"(\xb5/\xfd\x1002000$\x05\x0010\xcc0\xa8100000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"(\xb5/\xfd\x1002000$\x05\x0000\xcc0\xa8100d\x0000001000000000000000000000000000000000000000000000000000000000000000000000000\x000000000000000000000000000000000000000000000000000000000000000000000000000000",
"(\xb5/\xfd001\x00\x0000000000000000000",
"(\xb5/\xfd00\xec\x00\x00&@\x05\x05A7002\x02\x00\x02\x00\x02\x0000000000000000",
}

// This is a simple fuzzer to see if the decompressor panics.
Expand Down
3 changes: 3 additions & 0 deletions src/internal/zstd/literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func (r *Reader) readLiteralsFourStreams(data block, off, totalStreamsSize, rege
if totalStreamsSize < 6 {
return nil, r.makeError(off, "total streams size too small for jump table")
}
if regeneratedSize < 4 {
return nil, r.makeError(off, "regenerated size too small for jump table")
}

streamSize1 := binary.LittleEndian.Uint16(data[off:])
streamSize2 := binary.LittleEndian.Uint16(data[off+2:])
Expand Down

0 comments on commit c76e909

Please sign in to comment.