Skip to content

Commit b2d7bff

Browse files
authored
zstd: Trigger BCE by switching on lengths (#716)
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.
1 parent b3140ce commit b2d7bff

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

zstd/decodeheader.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (h *Header) Decode(in []byte) error {
152152
}
153153
b, in = in[:size], in[size:]
154154
h.HeaderSize += int(size)
155-
switch size {
155+
switch len(b) {
156156
case 1:
157157
h.DictionaryID = uint32(b[0])
158158
case 2:
@@ -182,7 +182,7 @@ func (h *Header) Decode(in []byte) error {
182182
}
183183
b, in = in[:fcsSize], in[fcsSize:]
184184
h.HeaderSize += int(fcsSize)
185-
switch fcsSize {
185+
switch len(b) {
186186
case 1:
187187
h.FrameContentSize = uint64(b[0])
188188
case 2:

zstd/framedec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (d *frameDec) reset(br byteBuffer) error {
167167
return err
168168
}
169169
var id uint32
170-
switch size {
170+
switch len(b) {
171171
case 1:
172172
id = uint32(b[0])
173173
case 2:
@@ -204,7 +204,7 @@ func (d *frameDec) reset(br byteBuffer) error {
204204
println("Reading Frame content", err)
205205
return err
206206
}
207-
switch fcsSize {
207+
switch len(b) {
208208
case 1:
209209
d.FrameContentSize = uint64(b[0])
210210
case 2:

0 commit comments

Comments
 (0)