René's URL Explorer Experiment


Title: Packer use-after-free via re-entrant `getbuffer()` during `pack()` · Issue #769 · msgpack/msgpack-python · GitHub

Open Graph Title: Packer use-after-free via re-entrant `getbuffer()` during `pack()` · Issue #769 · msgpack/msgpack-python

X Title: Packer use-after-free via re-entrant `getbuffer()` during `pack()` · Issue #769 · msgpack/msgpack-python

Description: Reported as a correctness bug Summary Packer runs user-controlled code in the middle of a pack() call, and that code can call getbuffer() to export the packer's internal buffer as a memoryview. If packing then continues and grows the buf...

Open Graph Description: Reported as a correctness bug Summary Packer runs user-controlled code in the middle of a pack() call, and that code can call getbuffer() to export the packer's internal buffer as a memoryview. If ...

X Description: Reported as a correctness bug Summary Packer runs user-controlled code in the middle of a pack() call, and that code can call getbuffer() to export the packer's internal buffer as a memoryview....

Opengraph URL: https://github.com/msgpack/msgpack-python/issues/769

X: @github

direct link

Domain: redirect.github.com

IPv4 address: 140.82.113.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Packer use-after-free via re-entrant `getbuffer()` during `pack()`","articleBody":"Reported as a correctness bug \n### Summary\n\n`Packer` runs user-controlled code in the middle of a `pack()` call, and that code can\ncall `getbuffer()` to export the packer's internal buffer as a memoryview. If packing then\ncontinues and grows the buffer, the growth reallocates it and frees the block the exported\nmemoryview still points at. Reading the memoryview afterwards is a heap use-after-free.\n\nThe guard meant to prevent this, `_check_exports()`, only runs at the entry of each public\nmethod. It never runs again during the recursive pack, so an export created partway through\nis invisible to it.\n\n## Affected version\n\n `msgpack._cmsgpack` (the C extension), class `Packer`.\n- HEAD `8a88e3d` (post-1.2.4); also reproduced on 1.2.2.\n- The pure-Python fallback is not affected: its buffer is a Python object, so an exported\n  view is not invalidated by a reallocation.\n\n### Details\n\nThe internal grow path is `msgpack_pack_write` in `pack.h`, which calls `PyMem_Realloc`\n(the free site). `getbuffer()` returns a memoryview backed by the raw buffer pointer and a\nlength captured at call time. There is no mechanism tying that export's lifetime to the\nbuffer, and `_check_exports()` is an entry-only check rather than an invariant held across\nthe pack.\n\nUser code runs mid-pack in at least three places, and the export can be created from any of\nthem:\n\n1. The `default` callback. This is the originally reported path (issue #733).\n2. `pack_map_pairs(obj)`, whose `for k, v in obj` loop runs `obj.__iter__` / `obj.__len__`.\n3. `pack(o)` where `o` is a `dict` or `list` subclass: `_pack_inner` runs `o.items()` or\n   iterates `o`.\n\n### The proposed fix (PR #735) is incomplete\n\nPR #735 adds one `_check_exports()` call in `_pack`, after the `default` callback returns.\nThat closes path 1 only. Paths 2 and 3 never execute that branch, so the use-after-free\nstill reproduces with #735 applied. Path 3 is a plain `pack()` of a dict, the most ordinary\ncall there is.\n\n### Proof of concept\n\nBuild the extension with AddressSanitizer and run the PoCs:\n\n```\n./build.sh                          # builds ASan+UBSan extension into .venv-asan\n./run.sh poc_f6.py                  # path 1: default callback\n./run.sh poc_f9_pack_map_pairs.py   # path 2: pack_map_pairs\n./run.sh poc_f9_dict_subclass.py    # path 3: plain pack() of a dict subclass\n```\n\npoc_f6.py\n```python\n# F6: Packer heap-UAF via re-entrant default= callback. Expect ASan heap-use-after-free.\nimport msgpack\nleaked = []\nclass Unsupported: pass\ndef default(o):\n    leaked.append(p.getbuffer())            # export a live view mid-pack\n    return b\"A\" * (2 * 1024 * 1024)         # big value -> realloc frees the view's buffer\np = msgpack.Packer(default=default, autoreset=False)\np.pack([Unsupported()])\nprint(bytes(leaked[0])[:16])                 # read through freed pointer\n```\n\u003cimg width=\"1593\" height=\"911\" alt=\"image\" src=\"https://github.com/user-attachments/assets/938d686e-0550-43c9-85dc-9a4236c0aa0f\" />\n\n\u003cimg width=\"1484\" height=\"949\" alt=\"image\" src=\"https://github.com/user-attachments/assets/5352fd81-11f3-40fe-ac24-c8f8a59cce07\" />\n\npoc_f9_pack_map_pairs.py\n```python\n# F9: same UAF via plain pack() of a dict subclass whose items() re-enters.\nimport msgpack\np = msgpack.Packer(autoreset=False)\np.pack(b\"prefix-content\")\nleaked = []\nclass EvilDict(dict):\n    def items(self):\n        leaked.append(p.getbuffer())\n        return [(b\"k\", b\"V\" * (4 * 1024 * 1024))]\np.pack(EvilDict({b\"x\": 1}))\nprint(bytes(leaked[0])[:16])\n```\n\u003cimg width=\"1393\" height=\"788\" alt=\"image\" src=\"https://github.com/user-attachments/assets/a30e34d6-eaa0-4e7f-8ef1-d632acd1a264\" />\n\n\u003cimg width=\"1622\" height=\"943\" alt=\"image\" src=\"https://github.com/user-attachments/assets/2bed1794-8c2b-450b-b2c0-b03daded589f\" />\n\n\n\nPath 3, the shortest trigger:\npoc_f9_dict_subclass.py\n\n```python\n# F9: same UAF, reached via pack_map_pairs iteration (NOT the default path #735 patches).\nimport msgpack\np = msgpack.Packer(autoreset=False)\np.pack(b\"prefix-content-to-make-buffer-nonempty\")\nleaked = []\nclass EvilPairs:\n    def __len__(self): return 1\n    def __iter__(self):\n        leaked.append(p.getbuffer())\n        yield (b\"k\", b\"V\" * (4 * 1024 * 1024))\np.pack_map_pairs(EvilPairs())\nprint(bytes(leaked[0])[:16])\n```\n\u003cimg width=\"1214\" height=\"829\" alt=\"image\" src=\"https://github.com/user-attachments/assets/4fc11b7c-d629-40b4-8834-7815fb787f33\" />\n\n\u003cimg width=\"1581\" height=\"943\" alt=\"image\" src=\"https://github.com/user-attachments/assets/3f56191e-d038-4cc0-9755-8923643ae3f3\" />\n\nAddressSanitizer reports `heap-use-after-free`, a READ inside `PyBuffer_ToContiguous`,\nfreed by `realloc` in `msgpack_pack_write` at `pack.h:47`. Paths 1, 2, and 3 each show a\ndistinct free-site frame (`default` branch, `pack_map_pairs`, and `_pack_inner` dict\niteration respectively), confirming they are separate routes to the same corruption.\n\nA negative control (a re-entrant iterator that does not call `getbuffer()`) runs clean, so\nthe export is the trigger, not the re-entrancy alone.\n\n### Impact\n\nAlways a reliable crash. Whether it becomes an information leak depends on the buffer's\nsize class. With a small `buf_size`, the freed chunk returns to a glibc bin, so spraying\nsame-size `bytes` objects between the free and the read lets the stale view read back\nattacker-adjacent heap content (a canary reappeared 122 times, consistent across five\nruns). At the default 256KB `buf_size` the freed region heads toward unmapped memory and\nthe read segfaults, so there it stays a crash. The exported view is read-only and the\nlibrary only writes through the new pointer, so there is no write primitive.\n\n## Suggested fix\n\nMake \"no live export during a pack\" an invariant instead of patching call sites one at a\ntime. Either refuse the realloc while `exports > 0`, or set a flag for the duration of any\npack and have `__getbuffer__` refuse to export while it is set. The Unpacker already does\nthe latter with its `_unpacking` flag: it is set for the whole parse, including while decode\nhooks run, and every buffer-touching entry point checks it. Copying that pattern closes all\nthree paths at once.\n\n## References\n\n- Issue #733 (the default-callback path)\n- PR #735 (proposed fix, closes only the default-callback path)\n- PR #739 (earlier fix attempt, closed unmerged)","author":{"url":"https://github.com/AmirWilayah","@type":"Person","name":"AmirWilayah"},"datePublished":"2026-11-05T10:30:10Z","url":"https://github.com/msgpack/msgpack-python/issues/769"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:29db3824-28b8-3845-024f-527a9c77ac7f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA554:BD75D:5E6E8D:817C9F:6B07535C
html-safe-noncedf40e08340534ebf4ecbf19d323672386d232bda763d508419f33e35d856e007
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTU0OkJENzVEOjVFNkU4RDo4MTdDOUY6NkIwNzUzNUMiLCJ2aXNpdG9yX2lkIjoiNzA4ODIwMjk0NjY1MTMxMjk4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac269e0fa5c39cf7834dd591ba19f9d7c65d80c6114f8da26ded0fa2daae592920
hovercard-subject-tagissue:6221399433
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/msgpack/msgpack-python/769/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c3bad5a4e16b10964750f05a8ab45000103853919ea7513eccc93b38c14ab223/msgpack/msgpack-python/issues/769
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c3bad5a4e16b10964750f05a8ab45000103853919ea7513eccc93b38c14ab223/msgpack/msgpack-python/issues/769
og:image:altReported as a correctness bug Summary Packer runs user-controlled code in the middle of a pack() call, and that code can call getbuffer() to export the packer's internal buffer as a memoryview. If ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAmirWilayah
hostnamegithub.com
expected-hostnamegithub.com
None663b1a69a41309856ffd9403fa5b764f6c0f78a39a0a8f75fb2c205c96a947be
turbo-cache-controlno-preview
go-importgithub.com/msgpack/msgpack-python git https://github.com/msgpack/msgpack-python.git
octolytics-dimension-user_id198264
octolytics-dimension-user_loginmsgpack
octolytics-dimension-repository_id2242705
octolytics-dimension-repository_nwomsgpack/msgpack-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id2242705
octolytics-dimension-repository_network_root_nwomsgpack/msgpack-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseeffa2c0a160a75bd95d9ffcc6320197d7aea0d83
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://redirect.github.com/msgpack/msgpack-python/issues/769#start-of-content
https://redirect.github.com/
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-python%2Fissues%2F769
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-python%2Fissues%2F769
Sign uphttps://redirect.github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=msgpack%2Fmsgpack-python
Reloadhttps://redirect.github.com/msgpack/msgpack-python/issues/769
Reloadhttps://redirect.github.com/msgpack/msgpack-python/issues/769
Reloadhttps://redirect.github.com/msgpack/msgpack-python/issues/769
msgpackhttps://redirect.github.com/msgpack
msgpack-pythonhttps://redirect.github.com/msgpack/msgpack-python
Codehttps://redirect.github.com/msgpack/msgpack-python
Issues5 (5)https://redirect.github.com/msgpack/msgpack-python/issues
Pull requests21 (21)https://redirect.github.com/msgpack/msgpack-python/pulls
Discussionshttps://redirect.github.com/msgpack/msgpack-python/discussions
Actionshttps://redirect.github.com/msgpack/msgpack-python/actions
Security and quality2 (2)https://redirect.github.com/msgpack/msgpack-python/security
Insightshttps://redirect.github.com/msgpack/msgpack-python/insights
https://redirect.github.com/msgpack/msgpack-python
New issuehttps://redirect.github.com/login?return_to=https://github.com/msgpack/msgpack-python/issues/769
New issuehttps://redirect.github.com/login?return_to=https://github.com/msgpack/msgpack-python/issues/769
#770https://github.com/msgpack/msgpack-python/pull/770
Packer use-after-free via re-entrant getbuffer() during pack()https://redirect.github.com/msgpack/msgpack-python/issues/769#top
#770https://github.com/msgpack/msgpack-python/pull/770
https://github.com/AmirWilayah
AmirWilayahhttps://github.com/AmirWilayah
on Nov 5, 2026https://github.com/msgpack/msgpack-python/issues/769#issue-6221399433
Packer.pack() segfaults when its default callback calls getbuffer() #733https://github.com/msgpack/msgpack-python/issues/733
#735https://github.com/msgpack/msgpack-python/pull/735
#735https://github.com/msgpack/msgpack-python/pull/735
#735https://github.com/msgpack/msgpack-python/pull/735
https://github.com/user-attachments/assets/938d686e-0550-43c9-85dc-9a4236c0aa0f
https://github.com/user-attachments/assets/5352fd81-11f3-40fe-ac24-c8f8a59cce07
https://github.com/user-attachments/assets/a30e34d6-eaa0-4e7f-8ef1-d632acd1a264
https://github.com/user-attachments/assets/2bed1794-8c2b-450b-b2c0-b03daded589f
https://github.com/user-attachments/assets/4fc11b7c-d629-40b4-8834-7815fb787f33
https://github.com/user-attachments/assets/3f56191e-d038-4cc0-9755-8923643ae3f3
Packer.pack() segfaults when its default callback calls getbuffer() #733https://github.com/msgpack/msgpack-python/issues/733
Check exported buffers after the default callback returns #735https://github.com/msgpack/msgpack-python/pull/735
Refuse to resize the packer buffer while a memoryview is exported #739https://github.com/msgpack/msgpack-python/pull/739
Sign up for freehttps://redirect.github.com/signup?return_to=https://github.com/msgpack/msgpack-python/issues/769
Sign in to commenthttps://redirect.github.com/login?return_to=https://github.com/msgpack/msgpack-python/issues/769
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.