Explorar o código

Catch overflow when incrementing dst pointer.

Nigel Tao %!s(int64=9) %!d(string=hai) anos
pai
achega
6ad2a85e2f
Modificáronse 1 ficheiros con 2 adicións e 3 borrados
  1. 2 3
      decode.go

+ 2 - 3
decode.go

@@ -121,11 +121,10 @@ func Decode(dst, src []byte) ([]byte, error) {
 			return nil, errUnsupportedCopy4Tag
 		}
 
-		end := d + length
-		if offset > d || end > len(dst) {
+		if offset > d || length > len(dst)-d {
 			return nil, ErrCorrupt
 		}
-		for ; d < end; d++ {
+		for end := d + length; d != end; d++ {
 			dst[d] = dst[d-offset]
 		}
 	}