Potential fix for code scanning alert no. 8: Incorrect conversion between integer types

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 10:29:55 -04:00 committed by GitHub
parent 58818e1660
commit 21540df1d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"math"
"math/big" "math/big"
"sort" "sort"
"strconv" "strconv"
@ -58,8 +59,14 @@ func (b *Long) UnmarshalGraphQL(input interface{}) error {
if strings.HasPrefix(input, "0x") { if strings.HasPrefix(input, "0x") {
// apply leniency and support hex representations of longs. // apply leniency and support hex representations of longs.
value, err := hexutil.DecodeUint64(input) value, err := hexutil.DecodeUint64(input)
if err != nil {
return err
}
if value > math.MaxInt64 {
return fmt.Errorf("value %d exceeds int64 range", value)
}
*b = Long(value) *b = Long(value)
return err return nil
} else { } else {
value, err := strconv.ParseInt(input, 10, 64) value, err := strconv.ParseInt(input, 10, 64)
*b = Long(value) *b = Long(value)