Browse Source

specify the upper bound of dst when calling copy

gengbing 7 years ago
parent
commit
2bbadaf34b
1 changed files with 6 additions and 6 deletions
  1. 6 6
      block.go

+ 6 - 6
block.go

@@ -61,7 +61,7 @@ func UncompressBlock(src, dst []byte) (si int, err error) {
 			}
 			}
 			i := si
 			i := si
 			si += lLen
 			si += lLen
-			di += copy(dst[di:], src[i:si])
+			di += copy(dst[di:di+si-i], src[i:si])
 
 
 			if si >= sn {
 			if si >= sn {
 				return di, nil
 				return di, nil
@@ -97,7 +97,7 @@ func UncompressBlock(src, dst []byte) (si int, err error) {
 			di += bytesToCopy
 			di += bytesToCopy
 			mLen -= bytesToCopy
 			mLen -= bytesToCopy
 		}
 		}
-		di += copy(dst[di:], dst[i:i+mLen])
+		di += copy(dst[di:di+mLen], dst[i:i+mLen])
 	}
 	}
 }
 }
 
 
@@ -186,7 +186,7 @@ func CompressBlock(src, dst []byte, hashTable []int) (di int, err error) {
 		di++
 		di++
 
 
 		// Literals.
 		// Literals.
-		copy(dst[di:], src[anchor:anchor+lLen])
+		copy(dst[di:di+lLen], src[anchor:anchor+lLen])
 		di += lLen + 2
 		di += lLen + 2
 		anchor = si
 		anchor = si
 
 
@@ -230,7 +230,7 @@ func CompressBlock(src, dst []byte, hashTable []int) (di int, err error) {
 		// Incompressible.
 		// Incompressible.
 		return 0, nil
 		return 0, nil
 	}
 	}
-	di += copy(dst[di:], src[anchor:])
+	di += copy(dst[di:di+len(src)-anchor], src[anchor:])
 	return di, nil
 	return di, nil
 }
 }
 
 
@@ -347,7 +347,7 @@ func CompressBlockHC(src, dst []byte, depth int) (di int, err error) {
 		di++
 		di++
 
 
 		// Literals.
 		// Literals.
-		copy(dst[di:], src[anchor:anchor+lLen])
+		copy(dst[di:di+lLen], src[anchor:anchor+lLen])
 		di += lLen
 		di += lLen
 		anchor = si
 		anchor = si
 
 
@@ -392,6 +392,6 @@ func CompressBlockHC(src, dst []byte, depth int) (di int, err error) {
 		// Incompressible.
 		// Incompressible.
 		return 0, nil
 		return 0, nil
 	}
 	}
-	di += copy(dst[di:], src[anchor:])
+	di += copy(dst[di:di+len(src)-anchor], src[anchor:])
 	return di, nil
 	return di, nil
 }
 }