Skip to content

Reject negative array and map header sizes - #742

Merged
methane merged 1 commit into
msgpack:mainfrom
jakezwang:fix/negative-container-header-size
Sep 20, 2026
Merged

methane merged 1 commit into
msgpack:mainfrom
jakezwang:fix/negative-container-header-size

Conversation

@jakezwang

Copy link
Copy Markdown
Contributor

pack_array_header() and pack_map_header() accept negative sizes. The C extension wraps them to unsigned lengths, while the Python fallback can write a different MessagePack type entirely.

Reject negative sizes before writing to the buffer in both implementations. Regression tests also check that a rejected header leaves previously buffered data unchanged.

Validation: both complete test suites pass on Python 3.10, 3.13, and 3.15rc2; Ruff checks and package validation pass.