Add missing autoreset in Packer.pack_ext_type

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().
This commit is contained in:
Kadir Can Ozden 2026-02-20 15:00:07 +03:00
parent f9806368ae
commit b691a8e52c

View file

@ -861,6 +861,10 @@ class Packer:
self._buffer.write(b"\xc9" + struct.pack(">I", L))
self._buffer.write(struct.pack("B", typecode))
self._buffer.write(data)
if self._autoreset:
ret = self._buffer.getvalue()
self._buffer = BytesIO()
return ret
def _pack_array_header(self, n):
if n <= 0x0F: