Skip to content

Sequential decoding does not behave as expected #272

@BrianSipos

Description

@BrianSipos

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.12.3

What happened?

In cbor2 before version 5.8 I could construct a BytesIO buffer and sequentially decode items using a CBORDecoder object. Starting in 5.8 it appears that the decoder fp member is seeked to the end of the buffer and calling dec.fp.read() gives empty bytes because of that. In earlier versions, the decoder would leave the underlying fp cursor just past the last decoded CBOR item.

How can we reproduce the bug?

Here is a small script that succeeds with earlier versions and fails on line 9 with 5.8.0, where the cursor is reported as position 3 (EOF).

import cbor2
import io

data = bytes.fromhex('000102')

dec = cbor2.CBORDecoder(io.BytesIO(data))
assert 0 == dec.fp.tell()
assert 0 == dec.decode()
assert 1 == dec.fp.tell()
assert 1 == dec.decode()
assert 2 == dec.fp.tell()
assert bytes.fromhex('02') == dec.fp.read()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions