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
regeneratedSize that is too small will result in index out-of-bounds
behaviour for expanded output slices.

regeneratedSize should be greater than or equal to 6

Fixes: golang#63824
  • Loading branch information
aimuz committed Nov 6, 2023
1 parent 4cd201b commit cba040b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/internal/zstd/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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",
"(\xb5/\xfd00\xec\x00\x00V@\x05\x0517002\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 < 6 {
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 cba040b

Please sign in to comment.