Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Add missing autoreset in Packer.pack_ext_type#663

Open
bysiber wants to merge 1 commit intomsgpack:main from
bysiber:fix/pack-ext-type-autoreset
Open

Add missing autoreset in Packer.pack_ext_type #663
bysiber wants to merge 1 commit intomsgpack:main from
bysiber:fix/pack-ext-type-autoreset

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

Packer.pack_ext_type() writes to the internal buffer but never checks self._autoreset. Every other public pack method (pack, pack_map_pairs, pack_array_header, pack_map_header) has this pattern:

if self._autoreset:
 ret = self._buffer.getvalue()
 self._buffer = BytesIO()
 return ret

Without it, pack_ext_type() always returns None, and the packed ext data stays in the buffer. The next call to pack() then returns both the extension data and the new value concatenated together, corrupting the serialized stream.

packer = msgpack.Packer()
result = packer.pack_ext_type(5, b'\x01\x02\x03')
# result is None, expected bytes
packer.pack(99)
# Returns 7 bytes (ext header + ext data + int) instead of 1 byte

ThomasWaldmann reacted with eyes emoji
pack_ext_type writes to the internal buffer but never checks
self._autoreset, unlike every other public pack method. This means
it always returns None and the packed data leaks into the output of
the next pack() call, corrupting the serialized stream.
Add the same autoreset pattern used by pack(), pack_map_pairs(),
pack_array_header(), and pack_map_header().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /