Skip to content

Commit 3f760a6

Browse files
fix(security): add bounds checking for remaining unsafe number conversions
- Add bounds checking for uint64 to int64 conversion in RawQuantityResponse.ToInt64() - Add missing uint64 case in hexToDecimal() function with proper bounds checking - Ensure all large integer values are properly validated before conversion to prevent overflow These fixes address security vulnerabilities identified in the number conversion code, preventing potential integer overflow issues when processing blockchain data with large numeric values. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 34ce97d commit 3f760a6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cmd/monitorv2/renderer/tview_renderer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,12 @@ func hexToDecimal(value interface{}) (*big.Int, error) {
25642564
}
25652565
}
25662566
return big.NewInt(int64(v)), nil
2567+
case uint64:
2568+
if v > math.MaxInt64 {
2569+
log.Error().Uint64("value", v).Msg("Uint64 value exceeds int64 range, using MaxInt64")
2570+
v = math.MaxInt64
2571+
}
2572+
return big.NewInt(int64(v)), nil
25672573
case int64:
25682574
return big.NewInt(v), nil
25692575
case int:

rpctypes/rpctypes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7+
"math"
78
"math/big"
89
"strconv"
910
"strings"
@@ -675,8 +676,11 @@ func (r RawQuantityResponse) ToInt64() int64 {
675676
if err != nil {
676677
return 0
677678
}
679+
if result > math.MaxInt64 {
680+
log.Error().Uint64("value", result).Msg("Value exceeds int64 range, using MaxInt64")
681+
return math.MaxInt64
682+
}
678683
return int64(result)
679-
680684
}
681685

682686
func (r *RawQuantityResponse) ToBigInt() *big.Int {

0 commit comments

Comments
 (0)