Skip to content

Commit

Permalink
Roll in a fix for #118 while we're at it
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekenre committed Jul 23, 2021
1 parent b21e20b commit 3b2dbeb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cbor2/decoder.py
Expand Up @@ -369,7 +369,11 @@ def decode_special(self, subtype):
return CBORSimpleValue(subtype)

# Major tag 7
return special_decoders[subtype](self)
try:
return special_decoders[subtype](self)
except KeyError as e:
raise CBORDecodeValueError(
"Undefined Reserved major type 7 subtype 0x%x" % subtype) from e

#
# Semantic decoders (major tag 6)
Expand Down
4 changes: 3 additions & 1 deletion source/decoder.c
Expand Up @@ -1606,7 +1606,9 @@ decode_special(CBORDecoderObject *self, uint8_t subtype)
case 27: return CBORDecoder_decode_float64(self);
case 31: CBOR2_RETURN_BREAK;
default:
// XXX Raise exception?
PyErr_Format(
_CBOR2_CBORDecodeValueError,
"Undefined Reserved major type 7 subtype 0x%x", subtype);
break;
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_decoder.py
Expand Up @@ -697,3 +697,13 @@ def test_invalid_cbor(impl):
'4c271579b01633a3ef6271be5c225eb2'
)
)


@pytest.mark.parametrize('data, expected', [
('fc', '1c'), ('fd', '1d'), ('fe', '1e')
],
)
def test_reserved_special_tags(impl, data, expected):
with pytest.raises(impl.CBORDecodeValueError) as exc_info:
impl.loads(unhexlify(data))
assert exc_info.value.args[0] == "Undefined Reserved major type 7 subtype 0x" + expected

0 comments on commit 3b2dbeb

Please sign in to comment.