From d445a083108997837dbdaf12508a60f71c040007 Mon Sep 17 00:00:00 2001 From: Romeo Rosete Date: Tue, 20 May 2025 11:14:25 -0400 Subject: [PATCH] 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> --- accounts/usbwallet/trezor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/accounts/usbwallet/trezor.go b/accounts/usbwallet/trezor.go index d4862d161b..97706d7ce2 100644 --- a/accounts/usbwallet/trezor.go +++ b/accounts/usbwallet/trezor.go @@ -294,6 +294,9 @@ func (w *trezorDriver) trezorExchange(req proto.Message, results ...proto.Messag if err != nil { return 0, err } + if len(data) > math.MaxInt-8 { + return 0, errors.New("serialized data too large") + } payload := make([]byte, 8+len(data)) copy(payload, []byte{0x23, 0x23}) binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))