René's URL Explorer Experiment


Title: fix: avoid memory leak when decoding invalid nested arrays by KowalskiThomas · Pull Request #671 · msgpack/msgpack-python · GitHub

Open Graph Title: fix: avoid memory leak when decoding invalid nested arrays by KowalskiThomas · Pull Request #671 · msgpack/msgpack-python

X Title: fix: avoid memory leak when decoding invalid nested arrays by KowalskiThomas · Pull Request #671 · msgpack/msgpack-python

Description: What is this PR? This PR fixes a memory leak that was detected (accidentally) through fuzzing. The leak happens in some cases when trying to decode invalid data. When decoding an array, the unpacker uses a stack and pushes a new list to that stack for every nested array element. If it eventually reaches a point where the element to decode is problematic, it returns -2 which results in FormatError being raised, but unpack_clear lacks some memory freeing logic (only relevant in the problematic case -- the outermost list is freed but not the other ones) and the objects are lost forever. The leak can directly be observed by running the following reproducer, which pushes several nested lists, and eventually one undefined format byte. It results in returning an error, without freeing the intermediate list objects. The logic is run under tracemalloc, with explicit GC calls to avoid transient still-alive objects that would be freed at some point. The deeper the nesting, the more objects are leaked. import gc import tracemalloc import msgpack._cmsgpack as _c KWARGS = {"raw": False, "strict_map_key": False, "max_array_len": 1 << 20, "max_map_len": 1 << 20} N = 10000 for depth in range(1, 15): data = bytes([0x91] * depth + [0xC1]) gc.collect() tracemalloc.start() s1 = tracemalloc.take_snapshot() for _ in range(N): try: _c.unpackb(data, **KWARGS) except: pass gc.collect() s2 = tracemalloc.take_snapshot() tracemalloc.stop() objs = sum(s.count_diff for s in s2.compare_to(s1, "lineno") if s.count_diff > 0) print(f"depth={depth}: {objs / N:.1f} leaked obj/call")

Open Graph Description: What is this PR? This PR fixes a memory leak that was detected (accidentally) through fuzzing. The leak happens in some cases when trying to decode invalid data. When decoding an array, the unpacke...

X Description: What is this PR? This PR fixes a memory leak that was detected (accidentally) through fuzzing. The leak happens in some cases when trying to decode invalid data. When decoding an array, the unpacke...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:90dd5497-e014-4267-4d38-800ca24a4662
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAA86:14453C:B723FB:F72243:6A531BEB
html-safe-nonce6e2f413df635d9d115a3f1a7c0a195773372ba93230602249839fb3ca4badc31
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTg2OjE0NDUzQzpCNzIzRkI6RjcyMjQzOjZBNTMxQkVCIiwidmlzaXRvcl9pZCI6IjgyMTQyMjg0MjU0NDA5NTk0NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac637da02b730f7dc6c78f6aaee5f02f5b7fc351ed201118a3a0de35057ee1dc98
hovercard-subject-tagpull_request:3600972659
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/671/files
twitter:imagehttps://avatars.githubusercontent.com/u/14239160?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/14239160?s=400&v=4
og:image:altWhat is this PR? This PR fixes a memory leak that was detected (accidentally) through fuzzing. The leak happens in some cases when trying to decode invalid data. When decoding an array, the unpacke...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
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
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/msgpack/msgpack-python/pull/671/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-python%2Fpull%2F671%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmsgpack%2Fmsgpack-python%2Fpull%2F671%2Ffiles
Sign up https://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://github.com/msgpack/msgpack-python/pull/671/files
Reloadhttps://github.com/msgpack/msgpack-python/pull/671/files
Reloadhttps://github.com/msgpack/msgpack-python/pull/671/files
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
msgpack https://github.com/msgpack
msgpack-pythonhttps://github.com/msgpack/msgpack-python
Notifications https://github.com/login?return_to=%2Fmsgpack%2Fmsgpack-python
Fork 249 https://github.com/login?return_to=%2Fmsgpack%2Fmsgpack-python
Star 2.1k https://github.com/login?return_to=%2Fmsgpack%2Fmsgpack-python
Code https://github.com/msgpack/msgpack-python
Issues 3 https://github.com/msgpack/msgpack-python/issues
Pull requests 5 https://github.com/msgpack/msgpack-python/pulls
Discussions https://github.com/msgpack/msgpack-python/discussions
Actions https://github.com/msgpack/msgpack-python/actions
Security and quality 1 https://github.com/msgpack/msgpack-python/security
Insights https://github.com/msgpack/msgpack-python/pulse
Code https://github.com/msgpack/msgpack-python
Issues https://github.com/msgpack/msgpack-python/issues
Pull requests https://github.com/msgpack/msgpack-python/pulls
Discussions https://github.com/msgpack/msgpack-python/discussions
Actions https://github.com/msgpack/msgpack-python/actions
Security and quality https://github.com/msgpack/msgpack-python/security
Insights https://github.com/msgpack/msgpack-python/pulse
Sign up for GitHub https://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://github.com/login?return_to=%2Fmsgpack%2Fmsgpack-python%2Fissues%2Fnew%2Fchoose
methanehttps://github.com/methane
msgpack:mainhttps://github.com/msgpack/msgpack-python/tree/main
KowalskiThomas:kowalski/fix-avoid-memory-leakhttps://github.com/KowalskiThomas/msgpack-python/tree/kowalski/fix-avoid-memory-leak
Conversation 9 https://github.com/msgpack/msgpack-python/pull/671
Commits 2 https://github.com/msgpack/msgpack-python/pull/671/commits
Checks 25 https://github.com/msgpack/msgpack-python/pull/671/checks
Files changed 3 https://github.com/msgpack/msgpack-python/pull/671/files
fix: avoid memory leak when decoding invalid nested arrays https://github.com/msgpack/msgpack-python/pull/671/files#top
Show all changes 2 commits https://github.com/msgpack/msgpack-python/pull/671/files
406360b fix: eliminate memory leak when parsing incorrect nested arrays KowalskiThomas Apr 29, 2026 https://github.com/msgpack/msgpack-python/pull/671/commits/406360b3a8437f487dfd4732585f276c275649df
1b54a1e test: add regression test KowalskiThomas Apr 29, 2026 https://github.com/msgpack/msgpack-python/pull/671/commits/1b54a1ea667118c4d62ceeec1b5a1c052fe05321
Clear filters https://github.com/msgpack/msgpack-python/pull/671/files
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
_unpacker.pyx https://github.com/msgpack/msgpack-python/pull/671/files#diff-407b1aba76cd8909a978c41341f7fe756567d21c6dab7c7568ca6075614531b1
unpack_template.h https://github.com/msgpack/msgpack-python/pull/671/files#diff-a35fa6234add31e8d66397bdedad27eebc3da5e2a98acb6b5c6ad02acb7a3ae4
test_except.py https://github.com/msgpack/msgpack-python/pull/671/files#diff-9cd77a04aaa61e85f445c4ad4d8500b68a7be941526820c8c0289fb774f92270
msgpack/_unpacker.pyxhttps://github.com/msgpack/msgpack-python/pull/671/files#diff-407b1aba76cd8909a978c41341f7fe756567d21c6dab7c7568ca6075614531b1
View file https://github.com/KowalskiThomas/msgpack-python/blob/1b54a1ea667118c4d62ceeec1b5a1c052fe05321/msgpack/_unpacker.pyx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/msgpack/msgpack-python/pull/671/{{ revealButtonHref }}
https://github.com/msgpack/msgpack-python/pull/671/files#diff-407b1aba76cd8909a978c41341f7fe756567d21c6dab7c7568ca6075614531b1
https://github.com/msgpack/msgpack-python/pull/671/files#diff-407b1aba76cd8909a978c41341f7fe756567d21c6dab7c7568ca6075614531b1
msgpack/unpack_template.hhttps://github.com/msgpack/msgpack-python/pull/671/files#diff-a35fa6234add31e8d66397bdedad27eebc3da5e2a98acb6b5c6ad02acb7a3ae4
View file https://github.com/KowalskiThomas/msgpack-python/blob/1b54a1ea667118c4d62ceeec1b5a1c052fe05321/msgpack/unpack_template.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/msgpack/msgpack-python/pull/671/{{ revealButtonHref }}
https://github.com/msgpack/msgpack-python/pull/671/files#diff-a35fa6234add31e8d66397bdedad27eebc3da5e2a98acb6b5c6ad02acb7a3ae4
methanehttps://github.com/methane
Apr 30, 2026https://github.com/msgpack/msgpack-python/pull/671/files#r3166427237
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
KowalskiThomashttps://github.com/KowalskiThomas
Apr 30, 2026https://github.com/msgpack/msgpack-python/pull/671/files#r3166732591
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
msgpack-python/msgpack/unpack_template.hhttps://github.com/msgpack/msgpack-python/blob/0d600a33285c8ef968a4926840ccc6a096ae3e09/msgpack/unpack_template.h#L56
0d600a3https://github.com/msgpack/msgpack-python/commit/0d600a33285c8ef968a4926840ccc6a096ae3e09
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
Please reload this pagehttps://github.com/msgpack/msgpack-python/pull/671/files
https://github.com/msgpack/msgpack-python/pull/671/files#diff-a35fa6234add31e8d66397bdedad27eebc3da5e2a98acb6b5c6ad02acb7a3ae4
test/test_except.pyhttps://github.com/msgpack/msgpack-python/pull/671/files#diff-9cd77a04aaa61e85f445c4ad4d8500b68a7be941526820c8c0289fb774f92270
View file https://github.com/KowalskiThomas/msgpack-python/blob/1b54a1ea667118c4d62ceeec1b5a1c052fe05321/test/test_except.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/msgpack/msgpack-python/pull/671/{{ revealButtonHref }}
https://github.com/msgpack/msgpack-python/pull/671/files#diff-9cd77a04aaa61e85f445c4ad4d8500b68a7be941526820c8c0289fb774f92270
https://github.com/msgpack/msgpack-python/pull/671/files#diff-9cd77a04aaa61e85f445c4ad4d8500b68a7be941526820c8c0289fb774f92270
https://github.com/msgpack/msgpack-python/pull/671/files#diff-9cd77a04aaa61e85f445c4ad4d8500b68a7be941526820c8c0289fb774f92270
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

Viewport: width=device-width


URLs of crawlers that visited me.