Skip to content

Commit cbbfc93

Browse files
committed
add check before casting int64 to uint32
1 parent f9d08e4 commit cbbfc93

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

internal/v3marshaling.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package internal
22

33
import (
4+
"fmt"
5+
"math"
46
"reflect"
57

68
"go.dedis.ch/kyber/v4"
@@ -35,6 +37,12 @@ func UnmarshalPriShare(data []byte, suite Suite) (*share.PriShare, error) {
3537
constructors := make(protobuf.Constructors)
3638
constructors[reflect.TypeFor[kyber.Scalar]()] = func() interface{} { return suite.Scalar() }
3739
err := protobuf.DecodeWithConstructors(data, compatiblePriShare, constructors)
40+
41+
// Check for overflow on I
42+
if compatiblePriShare.I < 0 || compatiblePriShare.I > math.MaxUint32 {
43+
return nil, fmt.Errorf("cannot cast I as int64 to uint32 due to overflow")
44+
}
45+
3846
if err != nil {
3947
return nil, err
4048
}

0 commit comments

Comments
 (0)