Title: `Packer.pack()` segfaults when its `default` callback calls `getbuffer()` · Issue #733 · msgpack/msgpack-python · GitHub
Open Graph Title: `Packer.pack()` segfaults when its `default` callback calls `getbuffer()` · Issue #733 · msgpack/msgpack-python
X Title: `Packer.pack()` segfaults when its `default` callback calls `getbuffer()` · Issue #733 · msgpack/msgpack-python
Description: Summary If the default callback obtains a memoryview through getbuffer() and then returns a sufficiently large value, Packer.pack() reallocates its internal buffer while the memoryview still references the old storage. Accessing the memo...
Open Graph Description: Summary If the default callback obtains a memoryview through getbuffer() and then returns a sufficiently large value, Packer.pack() reallocates its internal buffer while the memoryview still refere...
X Description: Summary If the default callback obtains a memoryview through getbuffer() and then returns a sufficiently large value, Packer.pack() reallocates its internal buffer while the memoryview still refere...
Opengraph URL: https://github.com/msgpack/msgpack-python/issues/733
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Packer.pack()` segfaults when its `default` callback calls `getbuffer()`","articleBody":"### Summary\n\nIf the `default` callback obtains a memoryview through `getbuffer()` and then returns a sufficiently large value, `Packer.pack()` reallocates its internal buffer while the memoryview still references the old storage.\nAccessing the memoryview afterward causes a segmentation fault, and an ASan build reports a heap-use-after-free.\n\n### Versions\n\nmsgpack 1.2.2, CPython 3.12.3, Ubuntu 24.04 x86_64, glibc 2.39.\n\n### Reproducer\n\n```python\nimport msgpack\n\npacker = None\nexported = None\n\nclass Unsupported:\n pass\n\ndef default(obj):\n global exported\n exported = packer.getbuffer()\n return b\"A\" * (2 * 1024 * 1024)\n\npacker = msgpack.Packer(default=default, autoreset=False)\npacker.pack([Unsupported()])\nmsgpack.unpackb(exported)\n```\n\nRunning it produces:\n\n```console\nSegmentation fault (core dumped)\n```\n\n### Sanitizer result\n\nAn ASan build reports a heap-use-after-free in `unpack_execute`.\nThe allocation was freed by `msgpack_pack_write` after the callback exported a memoryview of the buffer.\n\n```text\nERROR: AddressSanitizer: heap-use-after-free\nREAD of size 1\n #0 unpack_execute msgpack/unpack_template.h:161\nfreed by:\n #1 msgpack_pack_write msgpack/pack.h:47\n```\n\nI found this while fuzzing Python C extension modules.\nIt looks like a bug to me, but I may be missing an intended constraint, so I would appreciate confirmation.\n","author":{"url":"https://github.com/marinelay","@type":"Person","name":"marinelay"},"datePublished":"2026-08-28T00:32:01Z","url":"https://github.com/msgpack/msgpack-python/issues/733"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:faf81320-a44f-2726-38dc-7f47e71da56d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A9F8:BD75D:5CCAD5:7F35D0:6B0752E3 |
| html-safe-nonce | e0ad535ea4308da054f627f2b5c2ac681710c97101bb7bca682c689a7e52b7cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUY4OkJENzVEOjVDQ0FENTo3RjM1RDA6NkIwNzUyRTMiLCJ2aXNpdG9yX2lkIjoiMzU2MzUxMzA1NTY1OTExOTMzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3e29500d059906f9f5552acca74302840824cc186d45dd7341f5a2586fcf5703 |
| hovercard-subject-tag | issue:5273385174 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/msgpack/msgpack-python/733/issue_layout |
| twitter:image | https://opengraph.githubassets.com/076dc01784f1aa758f0894222fe2c9d2a70ce677bf3ac1b5f2e6bcc44f9022ca/msgpack/msgpack-python/issues/733 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/076dc01784f1aa758f0894222fe2c9d2a70ce677bf3ac1b5f2e6bcc44f9022ca/msgpack/msgpack-python/issues/733 |
| og:image:alt | Summary If the default callback obtains a memoryview through getbuffer() and then returns a sufficiently large value, Packer.pack() reallocates its internal buffer while the memoryview still refere... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marinelay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 663b1a69a41309856ffd9403fa5b764f6c0f78a39a0a8f75fb2c205c96a947be |
| turbo-cache-control | no-preview |
| go-import | github.com/msgpack/msgpack-python git https://github.com/msgpack/msgpack-python.git |
| octolytics-dimension-user_id | 198264 |
| octolytics-dimension-user_login | msgpack |
| octolytics-dimension-repository_id | 2242705 |
| octolytics-dimension-repository_nwo | msgpack/msgpack-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2242705 |
| octolytics-dimension-repository_network_root_nwo | msgpack/msgpack-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | effa2c0a160a75bd95d9ffcc6320197d7aea0d83 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width