Skip to content

Decoding CBOR tag 5 with null mantissa raises TypeError instead of CBORDecodeValueError #286

@coco1629

Description

@coco1629

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

cbor2 version

5.8.0

Python version

3.9.18

What happened?

When decoding CBOR tag 5 (bigfloat) with a null mantissa, CBORDecoder.decode() raises TypeError instead of the expected CBORDecodeValueError. This is probably because the try/except in decode_bigfloat only covers self._decode() , leaving the Decimal(sig) * (2 ** Decimal(exp)) computation outside its scope.

How can we reproduce the bug?

data = bytes.fromhex("c58200f6")
obj = cbor2.CBORDecoder(io.BytesIO(data))
print(obj.decode())

trace:

Traceback (most recent call last):
  File "test.py", line 60, in <module>
    print(obj.decode())
TypeError: unsupported operand type(s) for *: 'NoneType' and 'decimal.Decimal'

Expected behavior: should raise CBORDecodeValueError, consistent with other invalid input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions