Jelajahi Sumber

Catch overflow when incrementing src pointers.

Nigel Tao 9 tahun lalu
induk
melakukan
e292361195
1 mengubah file dengan 2 tambahan dan 2 penghapusan
  1. 2 2
      decode.go

+ 2 - 2
decode.go

@@ -103,7 +103,7 @@ func Decode(dst, src []byte) ([]byte, error) {
 
 		case tagCopy1:
 			s += 2
-			if s > len(src) {
+			if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
 				return nil, ErrCorrupt
 			}
 			length = 4 + int(src[s-2])>>2&0x7
@@ -111,7 +111,7 @@ func Decode(dst, src []byte) ([]byte, error) {
 
 		case tagCopy2:
 			s += 3
-			if s > len(src) {
+			if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
 				return nil, ErrCorrupt
 			}
 			length = 1 + int(src[s-3])>>2