aboutsummaryrefslogtreecommitdiff
path: root/internal/crypt
diff options
context:
space:
mode:
Diffstat (limited to 'internal/crypt')
-rw-r--r--internal/crypt/rawDecrypt.go4
-rw-r--r--internal/crypt/rawEncrypt.go4
2 files changed, 7 insertions, 1 deletions
diff --git a/internal/crypt/rawDecrypt.go b/internal/crypt/rawDecrypt.go
index 30a202f..b82f0fb 100644
--- a/internal/crypt/rawDecrypt.go
+++ b/internal/crypt/rawDecrypt.go
@@ -26,6 +26,10 @@ func DecryptRawBytes(inputBytes []byte, password []byte) ([]byte, error) {
return nil, fmt.Errorf("decrypt: failed to parse header length: %w", err)
}
+ if headerLen < 0 || idx+1+headerLen > len(inputBytes) {
+ return nil, fmt.Errorf("decrypt: invalid header length %d", headerLen)
+ }
+
headerBytes := inputBytes[idx+1 : idx+1+headerLen]
headers, err := utils.GetFileHeaders(headerBytes)
if err != nil {
diff --git a/internal/crypt/rawEncrypt.go b/internal/crypt/rawEncrypt.go
index 79a1a54..77803e0 100644
--- a/internal/crypt/rawEncrypt.go
+++ b/internal/crypt/rawEncrypt.go
@@ -2,6 +2,7 @@ package crypt
import (
"fmt"
+ "strconv"
"gitlab.com/whiteboardguy/eno/internal/utils"
"golang.org/x/crypto/argon2"
@@ -34,7 +35,8 @@ func EncryptRawBytes(inputBytes []byte, password []byte) ([]byte, error) {
return nil, fmt.Errorf("encrypt: %w", err)
}
- target := make([]byte, 0, len(headerBytes)+len(encrypted)+20)
+ lenLen := len(strconv.Itoa(len(headerBytes)))
+ target := make([]byte, 0, lenLen+1+len(headerBytes)+len(encrypted))
target = fmt.Appendf(target, "%d:", len(headerBytes))
target = append(target, headerBytes...)
target = append(target, encrypted...)