Add missing autoreset in Packer.pack_ext_type by bysiber · Pull Request #663 · msgpack/msgpack-python
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