Skip to content

Commit 9a6473e

Browse files
committed
feat: Added fix for uint64 errors in MarshalCbor function
Signed-off-by: Akhil Repala <[email protected]>
1 parent 83da7ca commit 9a6473e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ledger/common/tx.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,26 @@ func (s TransactionMetadataSet) MarshalCBOR() ([]byte, error) {
433433
maxKey = k
434434
}
435435
}
436-
if maxKey > uint64(math.MaxInt-1) {
436+
// expectedCount64 is the length the array
437+
expectedCount64 := maxKey + 1
438+
if expectedCount64 > uint64(math.MaxInt) {
437439
return nil, errors.New("metadata set too large to encode as array")
438440
}
439-
expectedCount := int(maxKey + 1)
441+
expectedCount := int(expectedCount64) // #nosec G115 — bounded by check above
440442
if len(s) != expectedCount {
441443
contiguous = false
442444
} else {
443-
for i := 0; i < expectedCount; i++ {
444-
if _, ok := s[uint64(i)]; !ok {
445+
for i := uint64(0); i < expectedCount64; i++ {
446+
if _, ok := s[i]; !ok {
445447
contiguous = false
446448
break
447449
}
448450
}
449451
}
450452
if contiguous {
451453
arr := make([]any, expectedCount)
452-
for i := 0; i < expectedCount; i++ {
453-
arr[i] = metadatumToInterface(s[uint64(i)])
454+
for i := uint64(0); i < expectedCount64; i++ {
455+
arr[i] = metadatumToInterface(s[i])
454456
}
455457
return cbor.Encode(&arr)
456458
}

0 commit comments

Comments
 (0)