Skip to content

Commit

Permalink
fix: json bounds checks for uint32 and int32
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 21, 2024
1 parent a03ee41 commit d9a89c3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions types/known/wrapperspb/wrappers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wrapperspb

import (
"math"
"strconv"

"github.com/aperturerobotics/protobuf-go-lite/json"
Expand Down Expand Up @@ -149,7 +150,12 @@ func (x *Int32Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = Int32Value{Value: int32(s.ReadInt64())}
v := s.ReadInt64()
if v < math.MinInt32 || v > math.MaxInt32 {
s.SetErrorf("value out of range for int32: %v", v)
return
}
*x = Int32Value{Value: int32(v)}
}

// MarshalProtoJSON marshals a Int32Value to JSON.
Expand Down Expand Up @@ -181,7 +187,12 @@ func (x *UInt32Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = UInt32Value{Value: uint32(s.ReadUint64())}
v := s.ReadUint64()
if v > math.MaxUint32 {
s.SetErrorf("value out of range for uint32: %v", v)
return
}
*x = UInt32Value{Value: uint32(v)}
}

// MarshalProtoJSON marshals a UInt32Value to JSON.
Expand Down

0 comments on commit d9a89c3

Please sign in to comment.