@@ -63,25 +63,25 @@ func Decode(dst, src []byte) ([]byte, error) {
s++
case x == 60:
s += 2
- if s > len(src) {
+ if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
return nil, ErrCorrupt
}
x = uint(src[s-1])
case x == 61:
s += 3
x = uint(src[s-2]) | uint(src[s-1])<<8
case x == 62:
s += 4
x = uint(src[s-3]) | uint(src[s-2])<<8 | uint(src[s-1])<<16
case x == 63:
s += 5
x = uint(src[s-4]) | uint(src[s-3])<<8 | uint(src[s-2])<<16 | uint(src[s-1])<<24
@@ -111,7 +111,7 @@ func Encode(dst, src []byte) []byte {
t int // The last position with the same hash as s.
lit int // The start position of any pending literal bytes.
)
- for s+3 < len(src) {
+ for uint(s+3) < uint(len(src)) { // The uint conversions catch overflow from the +3.
// Update the hash table.
b0, b1, b2, b3 := src[s], src[s+1], src[s+2], src[s+3]
h := uint32(b0) | uint32(b1)<<8 | uint32(b2)<<16 | uint32(b3)<<24