Make arithemetic operations overflow safe (#41)
This commit is contained in:
1 parent
036c3f2ae5
commit
e74f1b661a
2 files changed
+3
-3
No files matched your search
+2
-1
@@ -80,7 +80,8 @@ func EncryptData(password string, data []byte) ([]byte, error) {
|
||||
nonce := sioutil.MustRandom(stream.NonceSize())
|
||||
|
||||
// ciphertext = salt || AEAD ID | nonce | encrypted data
|
||||
cLen := int64(len(salt)+1+len(nonce)+len(data)) + stream.Overhead(int64(len(data)))
|
||||
// cLen calculation: Modified by Hashicorp in 2026 to make arithmetic operations overflow-safe by casting to int64 before addition
|
||||
cLen := int64(len(salt)) + 1 + int64(len(nonce)) + int64(len(data)) + stream.Overhead(int64(len(data)))
|
||||
ciphertext := bytes.NewBuffer(make([]byte, 0, cLen)) // pre-alloc correct length
|
||||
|
||||
// Prefix the ciphertext with salt, AEAD ID and nonce
|
||||
|
||||
Reference in new issue
Block a user