File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments