Repository navigation
Check exported buffers after the default callback returns - #735
AbhinavMir wants to merge 1 commit into
Conversation
The default callback can export the internal buffer with getbuffer(). The packer then continues and can reallocate that buffer. The export points at freed memory after the reallocation. Call _check_exports() after the callback returns. The packer now raises BufferError. The pure Python packer already raises BufferError in this case.
There was a problem hiding this comment.
🟡 Changes recommended
Other supported user-code hooks can still export the buffer before a reallocating write.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents buffer invalidation after default exports the packer’s internal buffer.
Changes:
- Checks active exports after
defaultreturns. - Adds regression coverage for the unsafe reallocation scenario.
File summaries
| File | Description |
|---|---|
msgpack/_packer.pyx |
Adds post-callback export validation. |
test/test_buffer.py |
Tests exported-buffer safety during callbacks. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # The callback may have exported the internal buffer. | ||
| # Packing on would reallocate it and invalidate the export. | ||
| self._check_exports() |
|
Independent ASan verification (HEAD This patch only calls
On both unpatched HEAD and this branch the stored memoryview reads stale bytes (e.g. So this approach looks incomplete; the |
#733