Skip to content

Commit 31b99fb

Browse files
authored
zstd: Make load(32|64)32 safer and smaller (#788)
load3232 and load6432 now limit their slice to its length. This improves safety, since encoders can no longer look at the part beyond the length. It also produces several dozen fewer instructions for bounds checks.
1 parent 2f99358 commit 31b99fb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

zstd/zstd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ func matchLen(a, b []byte) (n int) {
128128
}
129129

130130
func load3232(b []byte, i int32) uint32 {
131-
return binary.LittleEndian.Uint32(b[i:])
131+
return binary.LittleEndian.Uint32(b[:len(b):len(b)][i:])
132132
}
133133

134134
func load6432(b []byte, i int32) uint64 {
135-
return binary.LittleEndian.Uint64(b[i:])
135+
return binary.LittleEndian.Uint64(b[:len(b):len(b)][i:])
136136
}
137137

138138
type byter interface {

0 commit comments

Comments
 (0)