Skip to content

Commit

Permalink
Fix cbor.SimpleValue encoding and decoding
Browse files Browse the repository at this point in the history
This commit resolves two issues:

1.  Encoding cbor.SimpleValue with values 24..31 should fail because
CBOR simple values 24..31 are reserved and they MUST NOT be encoded
according to RFC 8949.

This commit makes encoder return UnsupportedValueError when encoding
cbor.SimpleValue with values 24..31 because that would not be
a well-formed CBOR data item.

2. Decoding other CBOR types to cbor.SimpleValue should fail because
cbor.SimpleValue represents CBOR simple value (major type 7) which is
different from CBOR integers and shouldn't be used interchangeably.

This commit makes decoder return UnmarshalTypeError when decoding
other CBOR types to cbor.SimpleValue.
  • Loading branch information
fxamacker committed Jan 2, 2024
1 parent 95e432d commit bfcaa81
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 16 deletions.
5 changes: 0 additions & 5 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,6 @@ func (d *decoder) parseToValue(v reflect.Value, tInfo *typeInfo) error { //nolin
f := math.Float64frombits(val)
return fillFloat(t, f, v)
default: // ai <= 24
// Decode simple values (including false, true, null, and undefined)
if tInfo.nonPtrType == typeSimpleValue {
v.SetUint(val)
return nil
}
switch ai {
case 20, 21:
return fillBool(t, ai == 21, v)
Expand Down
Loading

0 comments on commit bfcaa81

Please sign in to comment.