René's URL Explorer Experiment


Title: Convert Packer's buf_size once by hdimer · Pull Request #726 · msgpack/msgpack-python · GitHub

Open Graph Title: Convert Packer's buf_size once by hdimer · Pull Request #726 · msgpack/msgpack-python

X Title: Convert Packer's buf_size once by hdimer · Pull Request #726 · msgpack/msgpack-python

Description: Fixes #723. Packer.__cinit__ takes buf_size as an untyped object, and Cython converts it to size_t separately at each of the two lines that use it: def __cinit__(self, buf_size=256*1024, **_kwargs): self.pk.buf = PyMem_Malloc(buf_size) # converts once if self.pk.buf == NULL: raise MemoryError("Unable to allocate internal buffer.") self.pk.buf_size = buf_size # converts again An object that answers differently each time therefore sizes the allocation from one answer and the recorded capacity from the other. Everything afterwards trusts the recorded capacity: if (len + l > bs) { /* pack.h:45 - bs is pk.buf_size */ ...grow... } memcpy(buf + len, data, l); so a payload that fits the recorded capacity but not the real block is copied straight past the allocation. On the reporter's example the packer holds 600 bytes, records 1 MiB, and pack(b"A" * 100000) writes 100000 bytes into the 600-byte block. The fix Type the parameter, so the conversion happens once during argument unpacking: def __cinit__(self, size_t buf_size=256*1024, **_kwargs): This is how Unpacker already takes read_size and max_buffer_size (_unpacker.pyx:330), and it leaves no local for a later reader to fold back. It also removes a smaller wart: previously a second conversion that raised would leave __cinit__ failing with pk.buf already allocated. Same converter (__Pyx_PyInt_As_size_t), so nothing user-visible moves. I checked the constructor's edge cases against a pre-fix build and they are identical, message for message: -1 gives OverflowError: can't convert negative value to size_t, 1 << 62 gives MemoryError, "x" and None give TypeError: an integer is required, and 0, 1.5, True and the default are accepted as before. Tests test_buf_size_is_converted_once asserts the object is queried exactly once. The overflow itself cannot be asserted portably (it takes the interpreter down rather than failing a test), so the test pins the invariant that prevents it. It fails on main with assert 2 == 1 and passes with the change. The skipif follows the existing convention in test_unpack.py, since fallback.py accepts buf_size and ignores it. The helper's __int__ is the load-bearing slot on Cython 3.2.5, with __index__ aliased to it so the test keeps counting if a future Cython routes through PyNumber_Index instead. Verified on CPython 3.14: full suite green in both the C-extension and MSGPACK_PUREPYTHON=1 configurations, and ruff check / ruff format clean. The reporter's reproducer no longer crashes. Disclosure: I used an AI assistant while investigating and writing this patch. I reproduced the overflow myself, confirmed the pre-fix crash and the edge-case parity against a locally built extension, and I stand behind the change.

Open Graph Description: Fixes #723. Packer.__cinit__ takes buf_size as an untyped object, and Cython converts it to size_t separately at each of the two lines that use it: def __cinit__(self, buf_size=256*1024, **_kwargs)...

X Description: Fixes #723. Packer.__cinit__ takes buf_size as an untyped object, and Cython converts it to size_t separately at each of the two lines that use it: def __cinit__(self, buf_size=256*1024, **_kwargs)...

Opengraph URL: https://github.com/msgpack/msgpack-python/pull/726

X: @github

direct link

Domain: redirect.github.com

IPv4 address: 140.82.114.4

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:0dd2ad0e-e658-dc41-0fc6-c15fb8b4aa79
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id911E:BD75D:471326:614E0D:6B074CD9
html-safe-noncec180b144ed8b39cb95af1d246ace583691d81f6a85e697a7a216f7e2542c72e3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTFFOkJENzVEOjQ3MTMyNjo2MTRFMEQ6NkIwNzRDRDkiLCJ2aXNpdG9yX2lkIjoiMjY5OTQ3NTQxOTM2Mjk3MDg0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9d87c9718b8856e6911773dfdcfa3ec05cfb60815267bd58ef39d894e96422c3
hovercard-subject-tagpull_request:4264971009
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/msgpack/msgpack-python/pull/726/files
twitter:imagehttps://avatars.githubusercontent.com/u/94395445?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/94395445?s=400&v=4
og:image:altFixes #723. Packer.__cinit__ takes buf_size as an untyped object, and Cython converts it to size_t separately at each of the two lines that use it: def __cinit__(self, buf_size=256*1024, **_kwargs)...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None26f151990bcb5b67b87df8b3f96ed340f849939d44e36f348402de5e39cca989
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecd00d8452bcb4e56a60ba7c0e61a697b46513fe9
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/msgpack/msgpack-python/pull/726/files#start-of-content
https://redirect.github.com/
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-python%2Fpull%2F726%2Ffiles
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%2Fpull%2F726%2Ffiles
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%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=msgpack%2Fmsgpack-python
Reloadhttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
Reloadhttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
Reloadhttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
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
Sign up for GitHub https://redirect.github.com/signup?return_to=%2Fmsgpack%2Fmsgpack-python%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://redirect.github.com/login?return_to=%2Fmsgpack%2Fmsgpack-python%2Fissues%2Fnew%2Fchoose
methanehttps://redirect.github.com/methane
msgpack:mainhttps://redirect.github.com/msgpack/msgpack-python/tree/main
hdimer:fix-buf-size-converted-twicehttps://redirect.github.com/hdimer/msgpack-python/tree/fix-buf-size-converted-twice
Conversation 0 https://redirect.github.com/msgpack/msgpack-python/pull/726
Commits 1 https://redirect.github.com/msgpack/msgpack-python/pull/726/commits
Checks 50 https://redirect.github.com/msgpack/msgpack-python/pull/726/checks
Files changed https://redirect.github.com/msgpack/msgpack-python/pull/726/files
Please reload this pagehttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
Convert Packer's buf_size once https://redirect.github.com/msgpack/msgpack-python/pull/726/files#top
Show all changes 1 commit https://redirect.github.com/msgpack/msgpack-python/pull/726/files
c701ef8 Convert Packer's buf_size once hdimer Aug 12, 2026 https://redirect.github.com/msgpack/msgpack-python/pull/726/commits/c701ef8b812284ff049a8f4f29e8f5f30c3bfd01
Clear filters https://redirect.github.com/msgpack/msgpack-python/pull/726/files
Please reload this pagehttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
Please reload this pagehttps://redirect.github.com/msgpack/msgpack-python/pull/726/files
_packer.pyx https://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-7cc44ebbdabe0581aecc8e519e34b721b2be1dbf2f07eb53160ef8e6073dec3a
test_pack.py https://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-5eef35562d420d353fe69f68a2bbbc9d15a8d2428f073b42607b3145513639f0
msgpack/_packer.pyxhttps://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-7cc44ebbdabe0581aecc8e519e34b721b2be1dbf2f07eb53160ef8e6073dec3a
View file https://redirect.github.com/hdimer/msgpack-python/blob/c701ef8b812284ff049a8f4f29e8f5f30c3bfd01/msgpack/_packer.pyx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/msgpack/msgpack-python/pull/726/{{ revealButtonHref }}
https://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-7cc44ebbdabe0581aecc8e519e34b721b2be1dbf2f07eb53160ef8e6073dec3a
https://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-7cc44ebbdabe0581aecc8e519e34b721b2be1dbf2f07eb53160ef8e6073dec3a
test/test_pack.pyhttps://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-5eef35562d420d353fe69f68a2bbbc9d15a8d2428f073b42607b3145513639f0
View file https://redirect.github.com/hdimer/msgpack-python/blob/c701ef8b812284ff049a8f4f29e8f5f30c3bfd01/test/test_pack.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/msgpack/msgpack-python/pull/726/{{ revealButtonHref }}
https://redirect.github.com/msgpack/msgpack-python/pull/726/files#diff-5eef35562d420d353fe69f68a2bbbc9d15a8d2428f073b42607b3145513639f0
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-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.