Repository navigation
Conversation
Packer only checked for live buffer exports on entry to pack(), pack_map_pairs() and pack_ext_type(). Python code that runs during packing (a default callback, the pairs iterable, a list or dict subclass) could call memoryview(packer), after which msgpack_pack_write() reallocated pk.buf and left the export pointing at freed memory. Refuse exports from __getbuffer__ while one of those methods is running. The pure Python Packer already raises BufferError in this case because BytesIO cannot be resized while exported.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Cython
Packerchecks for live buffer exports only on entry topack(),pack_map_pairs()andpack_ext_type(). Python code that runs mid-pack (adefaultcallback, thepairsiterable, a list or dict subclass) can callmemoryview(packer), and the nextmsgpack_pack_write()that grows the bufferPyMem_Reallocspk.bufunder that view. WithPacker(buf_size=16, autoreset=False, default=...)wheredefaultstoresmemoryview(packer)and returnsb"x" * 65536, the stored view readsb' 'instead of theb'\x91'array header, i.e. freed heap memory.__getbuffer__now raisesBufferErrorwhile one of those three methods is running, using a nesting counter so a reentrantpack()from a callback doesn't clear the outer guard. The pure PythonPackeralready raisesBufferErrorhere becauseBytesIOrefuses to resize while exported, so the new test intest_buffer.pypasses on both implementations and fails on the unpatched C extension.