Releases: agronholm/cbor2
6.0.0rc1
-
MAJOR REWRITE: The Python and C implementations of the encoder and decoder were replaced with a single, Rust-based implementation in the interest of maintainability.
Here are some of the highlights:
- Improved memory safety (100% safe-mode Rust)
- Complete elimination of reference leaks
- Support for free-threading and subinterpreters
- Substantially improved performance
- Improved decoder error handling where any non-base exception gets wrapped in a
CBORDecodeError - Iterative, rather than recursive decoding, meaning the container nesting depth is limited only by the available memory, rather than the C stack size
-
BACKWARD INCOMPATIBLE Changed the signature of the
tag_hookdecoder callables to accept (CBORTag,immutableas arguments instead ofCBORDecoder,CBORTag) -
BACKWARD INCOMPATIBLE Changed the signature of the
object_hookdecoder callables to accept (Mapping[Any, Any],bool) instead of (CBORDecoder,dict[Any, Any]) -
BACKWARD INCOMPATIBLE Removed the
break_markersingleton as no longer necessary -
BACKWARD INCOMPATIBLE Removed the
CBORDecodeValueErrorexception, instead chainingValueErrororTypeErrorto aCBORDecodeError -
BACKWARD INCOMPATIBLE Changed the decoding of semantic tag 261 to yield an
IPv4InterfaceorIPv6Interfaceif the address contains host bits -
BACKWARD INCOMPATIBLE Removed the individual decoding functions from the API as they were mistakenly called directly by users. Please open an issue if you need them back.
-
BACKWARD INCOMPATIBLE Changed the encoding of IP addresses to use the semantic tags 52 and 54 instead of the deprecated 260 and 261 (#232)
-
BACKWARD INCOMPATIBLE Dropped the deprecated
cbor2.decoderandcbor2.encodermodules – everything in the API is now importable directly fromcbor2 -
BACKWARD INCOMPATIBLE The
cbor2.FrozenDictclass has now been renamedfrozendictand is not available on Python 3.15 where the built-infrozendictclass must be used instead -
Added the
semantic_decodersdecoder option to add or override decoders for specific semantic tags -
Added the
immutabledecoder flag to always use immutable containers where possible when decoding a CBOR stream -
Added the
allow_indefinitedecoder option to optionally disallow indefinite-length strings and containers -
Dropped support for Python 3.9
-
Fixed the decoder not rejecting invalid two-byte simple value sequences (0xF800 - 0xF81F)
5.9.0
- Added the
max_depthdecoder parameter to limit the maximum allowed nesting level of containers, with a default value of 400 levels (CVE-2026-26209) - Changed the default
read_sizefrom 4096 to 1 for backwards compatibility. The buffered reads introduced in 5.8.0 could cause issues when code needs to access the stream position after decoding. Users can opt-in to faster decoding by passingread_size=4096when they don't need to access the stream directly after decoding. Added a direct read path forread_size=1to avoid buffer management overhead. (#275; PR by @andreer) - Fixed C encoder not respecting string referencing when encoding string-type datetimes (tag 0) (#254)
- Fixed a missed check for an exception in the C implementation of
CBOREncoder.encode_shared()(#287) - Fixed two reference/memory leaks in the C extension's long string decoder (#290 PR by @killiancowan82)
- Fixed C decoder ignoring the
str_errorssetting when decoding strings, and improved string decoding performance by using stack allocation for small strings and eliminating unnecessary conditionals. Benchmarks show 9-17% faster deserialization. (#255; PR by @andreer)
5.8.0
- Added readahead buffering to C decoder for improved performance. The decoder now uses a 4 KB buffer by default to reduce the number of read calls. Benchmarks show 20-140% performance improvements for decoding operations. (#268; PR by @andreer)
- Fixed Python decoder not preserving share index when decoding array items containing nested shareable tags, causing shared references to resolve to wrong objects (#267; PR by @andreer)
- Reset shared reference state at the start of each top-level encode/decode operation (#266; PR by @andreer)
5.7.1
5.7.0
5.6.5
- Published binary wheels for Python 3.13
5.6.4
- Fixed compilation of C extension failing on GCC 14
- Fixed compiler warnings when building C extension
5.6.3
- Fixed decoding of epoch-based dates being affected by the local time zone in the C extension
5.6.2
- Fixed
__hash__()of the C version of theCBORTagtype crashing when there's a recursive reference cycle - Fixed type annotation for the file object in
cbor2.dump(),cbor2.load(),CBOREncoderandCBORDecoderto beIO[bytes]instead ofBytesIO - Worked around a CPython bug that caused a
SystemErrorto be raised, or even a buffer overflow to occur when decoding a long text string that contained only ASCII characters - Changed the return type annotations of
cbor2.load()andcbor2.load()to returnAnyinstead ofobjectso as not to force users to make type casts
5.6.1
- Fixed use-after-free in the decoder's C version when prematurely encountering the end of stream
- Fixed the C version of the decoder improperly raising
CBORDecodeEOFwhen decoding a text string longer than 65536 bytes