mirror of
https://github.com/asdine/storm.git
synced 2025-09-26 19:01:14 +08:00
AES: Add guard for data length to prevent panicking
This commit is contained in:
@@ -62,6 +62,10 @@ func (c *AES) Marshal(v interface{}) ([]byte, error) {
|
|||||||
// Unmarshal unmarshals the given encrypted byte array to the given type
|
// Unmarshal unmarshals the given encrypted byte array to the given type
|
||||||
func (c *AES) Unmarshal(data []byte, v interface{}) error {
|
func (c *AES) Unmarshal(data []byte, v interface{}) error {
|
||||||
nonceSize := c.aesGCM.NonceSize()
|
nonceSize := c.aesGCM.NonceSize()
|
||||||
|
if len(data) < nonceSize {
|
||||||
|
return fmt.Errorf("not enough data for aes decryption (%d < %d)", len(data), nonceSize)
|
||||||
|
}
|
||||||
|
|
||||||
decrypted, err := c.aesGCM.Open(nil, data[:nonceSize], data[nonceSize:], nil)
|
decrypted, err := c.aesGCM.Open(nil, data[:nonceSize], data[nonceSize:], nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error decrypting data: %w", err)
|
return fmt.Errorf("error decrypting data: %w", err)
|
||||||
|
Reference in New Issue
Block a user