Skip to content

Commit

Permalink
zstd: Trigger BCE by switching on lengths (#716)
Browse files Browse the repository at this point in the history
This patches reduces the number of bounds checks in zstd, as reported by

	go build -gcflags="-d=ssa/check_bce/debug=1" |& wc -l

from 723 to 693.
  • Loading branch information
greatroar authored Dec 19, 2022
1 parent b3140ce commit b2d7bff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions zstd/decodeheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (h *Header) Decode(in []byte) error {
}
b, in = in[:size], in[size:]
h.HeaderSize += int(size)
switch size {
switch len(b) {
case 1:
h.DictionaryID = uint32(b[0])
case 2:
Expand Down Expand Up @@ -182,7 +182,7 @@ func (h *Header) Decode(in []byte) error {
}
b, in = in[:fcsSize], in[fcsSize:]
h.HeaderSize += int(fcsSize)
switch fcsSize {
switch len(b) {
case 1:
h.FrameContentSize = uint64(b[0])
case 2:
Expand Down
4 changes: 2 additions & 2 deletions zstd/framedec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (d *frameDec) reset(br byteBuffer) error {
return err
}
var id uint32
switch size {
switch len(b) {
case 1:
id = uint32(b[0])
case 2:
Expand Down Expand Up @@ -204,7 +204,7 @@ func (d *frameDec) reset(br byteBuffer) error {
println("Reading Frame content", err)
return err
}
switch fcsSize {
switch len(b) {
case 1:
d.FrameContentSize = uint64(b[0])
case 2:
Expand Down

0 comments on commit b2d7bff

Please sign in to comment.