Skip to content

Commit

Permalink
zstd: Make load(32|64)32 safer and smaller (#788)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greatroar committed Mar 24, 2023
1 parent 2f99358 commit 31b99fb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func matchLen(a, b []byte) (n int) {
}

func load3232(b []byte, i int32) uint32 {
return binary.LittleEndian.Uint32(b[i:])
return binary.LittleEndian.Uint32(b[:len(b):len(b)][i:])
}

func load6432(b []byte, i int32) uint64 {
return binary.LittleEndian.Uint64(b[i:])
return binary.LittleEndian.Uint64(b[:len(b):len(b)][i:])
}

type byter interface {
Expand Down

0 comments on commit 31b99fb

Please sign in to comment.