Check if data is long enough to be decrypted

This commit is contained in:
Jason Streifling 2025-02-03 10:40:33 +01:00
parent 344864f5b2
commit 1cf537662a

View File

@ -117,6 +117,9 @@ func aesDecrypt(c *Config, ciphertext string) (string, error) {
} }
nonceSize := gcm.NonceSize() nonceSize := gcm.NonceSize()
if len(data) < nonceSize {
return "", errors.New("ciphertext too short")
}
nonce, cipherText := data[:nonceSize], data[nonceSize:] nonce, cipherText := data[:nonceSize], data[nonceSize:]
plaintext, err := gcm.Open(nil, nonce, cipherText, nil) plaintext, err := gcm.Open(nil, nonce, cipherText, nil)