Title: C extension should reject ext_hook=None consistently with the Python fallback · Issue #762 · msgpack/msgpack-python · GitHub
Open Graph Title: C extension should reject ext_hook=None consistently with the Python fallback · Issue #762 · msgpack/msgpack-python
X Title: C extension should reject ext_hook=None consistently with the Python fallback · Issue #762 · msgpack/msgpack-python
Description: Description The C extension accepts ext_hook=None in both unpackb() and Unpacker.__init__(), while the pure-Python fallback raises TypeError. In msgpack/_unpacker.pyx, init_ctx() only assigns ctx.user.ext_hook when ext_hook is not None: ...
Open Graph Description: Description The C extension accepts ext_hook=None in both unpackb() and Unpacker.__init__(), while the pure-Python fallback raises TypeError. In msgpack/_unpacker.pyx, init_ctx() only assigns ctx.u...
X Description: Description The C extension accepts ext_hook=None in both unpackb() and Unpacker.__init__(), while the pure-Python fallback raises TypeError. In msgpack/_unpacker.pyx, init_ctx() only assigns ctx.u...
Opengraph URL: https://github.com/msgpack/msgpack-python/issues/762
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C extension should reject ext_hook=None consistently with the Python fallback","articleBody":"### Description\n\nThe C extension accepts `ext_hook=None` in both `unpackb()` and `Unpacker.__init__()`, while the pure-Python fallback raises `TypeError`.\n\nIn `msgpack/_unpacker.pyx`, `init_ctx()` only assigns `ctx.user.ext_hook` when `ext_hook is not None`:\n\n```cython\nif ext_hook is not None:\n if not PyCallable_Check(ext_hook):\n raise TypeError(\"ext_hook must be a callable.\")\n ctx.user.ext_hook = \u003cPyObject*>ext_hook\n```\n\nUnlike `object_hook` and `list_hook`, `ctx.user.ext_hook` is not initialized to `NULL`. This can leave an uninitialized pointer or retain a stale pointer when `Unpacker.__init__()` is called again.\n\nConsequently, decoding extension types may invoke a stale callback or crash the process.\n\n### Expected behavior\n\nSince `ext_hook` must be callable, the C extension should reject `None` and other non-callable values with `TypeError`, matching the pure-Python implementation.\n\n### Suggested fix\n\n- Initialize `ctx.user.ext_hook` to `NULL` along with `object_hook` and `list_hook`.\n- Remove the `if ext_hook is not None` condition and always validate that `ext_hook` is callable.\n- Add regression tests for both `unpackb()` and `Unpacker`, including reinitialization.\n\n### Credit\n\nThanks to @FanzyBear for reporting this issue and providing a detailed analysis and reproducer through a private security report.","author":{"url":"https://github.com/methane","@type":"Person","name":"methane"},"datePublished":"2026-10-30T06:51:16Z","url":"https://github.com/msgpack/msgpack-python/issues/762"}
| 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:6fe261d0-ae8f-7458-1d12-1e15a84e925e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86EC:1807E5:2EB3A6:3D389B:6B07622A |
| html-safe-nonce | 2c85fd1553841af135b783b13bf1166c6692fa8f2bc2d1e7b2db8a379d219884 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkVDOjE4MDdFNToyRUIzQTY6M0QzODlCOjZCMDc2MjJBIiwidmlzaXRvcl9pZCI6IjYwNzg0NDg0NjAyNTUxNTg4MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d4b39c25dfedd70991f7440a98d1ee90c9326522d2f277e63eaeeb0675001afb |
| hovercard-subject-tag | issue:6114632447 |
| 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/762/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b1386ea15791b7154ea067411663971bc7a2f50a271bcd5157e4d4c3c457870a/msgpack/msgpack-python/issues/762 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b1386ea15791b7154ea067411663971bc7a2f50a271bcd5157e4d4c3c457870a/msgpack/msgpack-python/issues/762 |
| og:image:alt | Description The C extension accepts ext_hook=None in both unpackb() and Unpacker.__init__(), while the pure-Python fallback raises TypeError. In msgpack/_unpacker.pyx, init_ctx() only assigns ctx.u... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | methane |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7a557ecc960a3ae6e299fc66b0bc9132072f8860191648e6749fee5d3ff00d82 |
| 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 | bd845eb7947c1ed8c850f7ab415a51339d162de3 |
| 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