Potential fix for code scanning alert no. 4: Size computation for allocation may overflow

Romeo Rosete

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Romeo Rosete 2025-05-20 11:14:25 -04:00 committed by GitHub
parent a32388b614
commit d445a08310
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -294,6 +294,9 @@ func (w *trezorDriver) trezorExchange(req proto.Message, results ...proto.Messag
if err != nil { if err != nil {
return 0, err return 0, err
} }
if len(data) > math.MaxInt-8 {
return 0, errors.New("serialized data too large")
}
payload := make([]byte, 8+len(data)) payload := make([]byte, 8+len(data))
copy(payload, []byte{0x23, 0x23}) copy(payload, []byte{0x23, 0x23})
binary.BigEndian.PutUint16(payload[2:], trezor.Type(req)) binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))