Skip to content

Commit 8b2690c

Browse files
authored
fix(cbor): return decode error if int too large (#894)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent e462f18 commit 8b2690c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cbor/decode.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package cbor
1717
import (
1818
"bytes"
1919
"fmt"
20+
"math"
2021
"reflect"
2122
"sync"
2223

@@ -68,6 +69,9 @@ func DecodeIdFromList(cborData []byte) (int, error) {
6869
switch v := tmp.Value().([]interface{})[0].(type) {
6970
// The upstream CBOR library uses uint64 by default for numeric values
7071
case uint64:
72+
if v > uint64(math.MaxInt) {
73+
return 0, fmt.Errorf("decoded numeric value too large: uint64 > int")
74+
}
7175
return int(v), nil
7276
default:
7377
return 0, fmt.Errorf("first list item was not numeric, found: %v", v)

0 commit comments

Comments
 (0)