René's URL Explorer Experiment


Title: Fix DecompressMemMapReader.read returning b'' before EOF (#120) by mvanhorn · Pull Request #135 · gitpython-developers/gitdb · GitHub

Open Graph Title: Fix DecompressMemMapReader.read returning b'' before EOF (#120) by mvanhorn · Pull Request #135 · gitpython-developers/gitdb

X Title: Fix DecompressMemMapReader.read returning b'' before EOF (#120) by mvanhorn · Pull Request #135 · gitpython-developers/gitdb

Description: Summary Closes #120 DecompressMemMapReader.read(N) could return b'' before _br == _s when N was small enough that the underlying zlib.decompress(indata, N) consumed input bytes without producing output (e.g. while ingesting the zlib header / dictionary frames). Callers using the standard while chunk := stream.read(N) idiom terminated at the first empty chunk -- before reaching the actual end of the uncompressed object. Reproduced with chunk sizes 1, 4, 16 against a 13 KB stream of compressible data. Why the original guard existed The previous if dcompdat and ... guard at the recursion site was added so that compressed_bytes_read() could drive read() in a scrub-loop that intentionally manipulates _br = 0 while the inner zlib object is already past EOF. Without that guard, the scrub loop would recurse forever because _br < _s stays true. Fix Convert the recursive "refill to size" branch into an iterative loop around the existing decompress block. The loop terminates when: len(dcompdat) >= size (caller's request satisfied), OR _br >= _s (uncompressed object fully read), OR Inner zlib produced an empty chunk AND (zlib has hit EOF, OR the input window has run off self._m, OR no compressed bytes were consumed on this turn). Condition 3 preserves the compressed_bytes_read() scrub safety: once the inner zip is at EOF, the loop breaks instead of looping forever. It also bounds the truncated-stream case (zip.eof never becomes true) by the input-exhaustion guard, and bounds the crafted "many empty deflate blocks" attack -- previously this could blow Python's recursion depth at ~1500+ stored-block headers because each recursion only consumed a handful of input bytes; the iterative form walks the stream forward without growing the stack. Tests New: test_decompress_reader_chunked_read_does_not_terminate_early reads a 13 KB highly-compressible stream with chunk sizes 1, 4, 16, 64 and asserts the full payload is returned and _br == _s. Existing: gitdb/test/ (24 tests) all pass, including test_decompress_reader_special_case and test_pack -- both exercise the compressed_bytes_read scrub path. $ pytest gitdb/test ======================== 24 passed, 1 skipped in 7.10s ======================== Manual smoke import zlib from gitdb import DecompressMemMapReader data = b"hello world! " * 1000 zdata = zlib.compress(data) for chunk_size in (1, 4, 16, 64, 4096): r = DecompressMemMapReader(zdata, close_on_deletion=False, size=len(data)) out = b"" while chunk := r.read(chunk_size): out += chunk assert out == data, chunk_size (Pre-fix this fails for chunk_size in (1, 4, 16).) Truncated input is handled the same as before: read() returns whatever was decoded so far, then b'', instead of looping or raising. The crafted recursion-depth attack (~5000 empty deflate blocks ahead of one valid block) now decodes correctly instead of raising RecursionError.

Open Graph Description: Summary Closes #120 DecompressMemMapReader.read(N) could return b'' before _br == _s when N was small enough that the underlying zlib.decompress(indata, N) consumed input bytes without prod...

X Description: Summary Closes #120 DecompressMemMapReader.read(N) could return b&#39;&#39; before _br == _s when N was small enough that the underlying zlib.decompress(indata, N) consumed input bytes with...

Opengraph URL: https://github.com/gitpython-developers/gitdb/pull/135

X: @github

direct link

Domain: redirect.github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:63d9f09e-ecae-3156-4314-24b08aa788a2
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDF3C:A9D99:2195BF1:2D63757:6A59A21A
html-safe-noncecaca8a4e3af558cc9786bcb2a2f0904349e60dd228366145981a520f46051034
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjNDOkE5RDk5OjIxOTVCRjE6MkQ2Mzc1Nzo2QTU5QTIxQSIsInZpc2l0b3JfaWQiOiIyOTI4MDE2NDQwMjYyNTAwODkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac97536dd840e958fad1183a4dd1d1d2dbda5e39b06879c76a6966e6a7975031dd
hovercard-subject-tagpull_request:3649338387
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/gitpython-developers/gitdb/pull/135/files
twitter:imagehttps://avatars.githubusercontent.com/u/455140?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/455140?s=400&v=4
og:image:altSummary Closes #120 DecompressMemMapReader.read(N) could return b'' before _br == _s when N was small enough that the underlying zlib.decompress(indata, N) consumed input bytes without prod...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonea540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/gitpython-developers/gitdb git https://github.com/gitpython-developers/gitdb.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126093
octolytics-dimension-repository_nwogitpython-developers/gitdb
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126093
octolytics-dimension-repository_network_root_nwogitpython-developers/gitdb
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
release0b971869dd75eec26500a9de7e85b8137c6bf0f6
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files#start-of-content
https://redirect.github.com/
Sign in https://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2Fgitdb%2Fpull%2F135%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://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2Fgitdb%2Fpull%2F135%2Ffiles
Sign up https://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=gitpython-developers%2Fgitdb
Reloadhttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Reloadhttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Reloadhttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Please reload this pagehttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
gitpython-developers https://redirect.github.com/gitpython-developers
gitdbhttps://redirect.github.com/gitpython-developers/gitdb
Notifications https://redirect.github.com/login?return_to=%2Fgitpython-developers%2Fgitdb
Fork 69 https://redirect.github.com/login?return_to=%2Fgitpython-developers%2Fgitdb
Star 225 https://redirect.github.com/login?return_to=%2Fgitpython-developers%2Fgitdb
Code https://redirect.github.com/gitpython-developers/gitdb
Issues 6 https://redirect.github.com/gitpython-developers/gitdb/issues
Pull requests 0 https://redirect.github.com/gitpython-developers/gitdb/pulls
Discussions https://redirect.github.com/gitpython-developers/gitdb/discussions
Actions https://redirect.github.com/gitpython-developers/gitdb/actions
Security and quality 0 https://redirect.github.com/gitpython-developers/gitdb/security
Insights https://redirect.github.com/gitpython-developers/gitdb/pulse
Code https://redirect.github.com/gitpython-developers/gitdb
Issues https://redirect.github.com/gitpython-developers/gitdb/issues
Pull requests https://redirect.github.com/gitpython-developers/gitdb/pulls
Discussions https://redirect.github.com/gitpython-developers/gitdb/discussions
Actions https://redirect.github.com/gitpython-developers/gitdb/actions
Security and quality https://redirect.github.com/gitpython-developers/gitdb/security
Insights https://redirect.github.com/gitpython-developers/gitdb/pulse
Sign up for GitHub https://redirect.github.com/signup?return_to=%2Fgitpython-developers%2Fgitdb%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://redirect.github.com/login?return_to=%2Fgitpython-developers%2Fgitdb%2Fissues%2Fnew%2Fchoose
Byronhttps://redirect.github.com/Byron
gitpython-developers:masterhttps://redirect.github.com/gitpython-developers/gitdb/tree/master
mvanhorn:fix/120-empty-read-before-eofhttps://redirect.github.com/mvanhorn/gitdb/tree/fix/120-empty-read-before-eof
Conversation 5 https://redirect.github.com/gitpython-developers/gitdb/pull/135
Commits 2 https://redirect.github.com/gitpython-developers/gitdb/pull/135/commits
Checks 8 https://redirect.github.com/gitpython-developers/gitdb/pull/135/checks
Files changed 2 https://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Fix DecompressMemMapReader.read returning b'' before EOF (#120) https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#top
Show all changes 2 commits https://redirect.github.com/gitpython-developers/gitdb/pull/135/files
81cf3e5 Fix DecompressMemMapReader.read returning b'' before EOF mvanhorn May 8, 2026 https://redirect.github.com/gitpython-developers/gitdb/pull/135/commits/81cf3e5fd2a19842b21f30e158b7f41bf6d91f28
ed41d2c Apply suggestions from code review Byron May 9, 2026 https://redirect.github.com/gitpython-developers/gitdb/pull/135/commits/ed41d2c26f77bc58a5b8f51100a300c4e09a7a30
Clear filters https://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Please reload this pagehttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
Please reload this pagehttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files
stream.py https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-f6440f5e0cda5d1378b640ec31f3af66718c868057a5b4971612a2bc0bc8a563
test_stream.py https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-1003490311c8f24a8e8107692cc98f0beb0ed654bce2485ede78d5fca9bb9c50
gitdb/stream.pyhttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-f6440f5e0cda5d1378b640ec31f3af66718c868057a5b4971612a2bc0bc8a563
View file https://redirect.github.com/mvanhorn/gitdb/blob/ed41d2c26f77bc58a5b8f51100a300c4e09a7a30/gitdb/stream.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/gitpython-developers/gitdb/pull/135/{{ revealButtonHref }}
https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-f6440f5e0cda5d1378b640ec31f3af66718c868057a5b4971612a2bc0bc8a563
https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-f6440f5e0cda5d1378b640ec31f3af66718c868057a5b4971612a2bc0bc8a563
gitdb/test/test_stream.pyhttps://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-1003490311c8f24a8e8107692cc98f0beb0ed654bce2485ede78d5fca9bb9c50
View file https://redirect.github.com/mvanhorn/gitdb/blob/ed41d2c26f77bc58a5b8f51100a300c4e09a7a30/gitdb/test/test_stream.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/gitpython-developers/gitdb/pull/135/{{ revealButtonHref }}
https://redirect.github.com/gitpython-developers/gitdb/pull/135/files#diff-1003490311c8f24a8e8107692cc98f0beb0ed654bce2485ede78d5fca9bb9c50
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.