René's URL Explorer Experiment


Title: gh-111791: delegating extraction to zipfile module's extractall() method by sepastian · Pull Request #111824 · python/cpython · GitHub

Open Graph Title: gh-111791: delegating extraction to zipfile module's extractall() method by sepastian · Pull Request #111824 · python/cpython

X Title: gh-111791: delegating extraction to zipfile module's extractall() method by sepastian · Pull Request #111824 · python/cpython

Description: shutil.unpack_archive: deletage extracting ZIP files to zipfile (#111791) gh-111791: rely on `zipfile.extractall` when extraxting ZIP archives, preventing false negatives and code duplication As reported in #111791, if the path of a file inside a ZIP file contains "..", e.g. myfile..txt (probably misspelled), shutil.unpack_archive will silently skip extracting the file, because it wrongly assumes a relative path. This is problematic for two reasons: The current implementation of shutil.unpack_archive wrongly identifies relative path components. Scanning for ".." does not tell whether a path contains relative components, or not; one must scan for "../" instead. Besides, files inside a ZIP archive described through relative paths should be extracted, see below. Python's own zipfile module and the unzip are handling relative path components "../"and names containins ".." correctly. For reference, the man unzip page says: For security reasons, unzip normally removes parent dir path components (../) from the names of extracted file. This safety feature (new for version 5.50) prevents unzip from accidentally writing files to sensitive areas outside the active extraction folder tree head. Solution: delegate extracting ZIP archives to Python's own zipfile.extractall method. Appendix The following example shows, how extracting a ZIP archive containing paths containing relative components "../" and files with names containing ".." differs in shutil.unpack_archive, zipfile.extractall and the Linux tool unzip. # Create some files and directories. $ cd /tmp $ mkdir -p a/b/c $ touch a/a.txt a/a..txt a/b/b.txt a/b/b..txt a/b/c/c.txt a/b/c/c..txt $ find a a a/b a/b/b.txt a/b/b..txt a/b/c a/b/c/c.txt a/b/c/c..txt a/a.txt a/a..txt # Create a ZIP file for testing. $ cd /tmp/a/b $ zip /tmp/test.zip ../a.txt /tmp/a/b/c/c.txt ../../a/b/b.txt # Inspect the newly created ZIP file. $ zipinfo /tmp/test.zip zipinfo /tmp/test.zip Archive: /tmp/test.zip Zip file size: 482 bytes, number of entries: 3 -rw-rw-r-- 3.0 unx 0 bx stor 23-Nov-07 16:03 ../a.txt -rw-rw-r-- 3.0 unx 0 bx stor 23-Nov-07 16:04 tmp/a/b/c/c.txt -rw-rw-r-- 3.0 unx 0 bx stor 23-Nov-07 16:03 ../../a/b/b.txt 3 files, 0 bytes uncompressed, 0 bytes compressed: 0.0% # Prepare directories holding extraction results. $ mkdir -p /tmp/extract/unzip /tmp/extract/zipfile /tmp/extract/shutil # Extract using 'unzip' extracts all files # and warns about relative path components. $ cd /tmp/extract/unzip $ unzip /tmp/test.zip Archive: /tmp/test.zip warning: skipped "../" path component(s) in ../a.txt extracting: a.txt extracting: tmp/a/b/c/c.txt warning: skipped "../" path component(s) in ../../a/b/b.txt extracting: a/b/b.txt $ find . ./a ./a/b ./a/b/b.txt ./tmp ./tmp/a ./tmp/a/b ./tmp/a/b/c ./tmp/a/b/c/c.txt ./a.txt # Extract using 'zipfile' (CLI). $ cd /tmp/extract/zipfile $ python3 -m zipfile -e /tmp/test.zip . $ find . ./a ./a/b ./a/b/b.txt ./tmp ./tmp/a ./tmp/a/b ./tmp/a/b/c ./tmp/a/b/c/c.txt ./a.txt # Extract using 'shutil.unpack_archive'. $ cd /tmp/extract/shutil $ python3 -c 'import shutil; shutil.unpack_archive("/tmp/test.zip",".")' $ find . ./tmp ./tmp/a ./tmp/a/b ./tmp/a/b/c ./tmp/a/b/c/c.txt # As can be seen, and as can be confirmed using `diff`, # zipfile and unzip produce the same result, # while shutil silently skips paths containing "..", # i.e. both names containing ".." and paths containing # actual relative components. # Diff. $ cd /tmp/extract $ diff -r zipfile/ unzip/ $ diff -r unzip/ shutil/ Only in unzip/: a Only in unzip/: a..txt Only in unzip/: a.txt Only in unzip/: tmp

Open Graph Description: shutil.unpack_archive: deletage extracting ZIP files to zipfile (#111791) gh-111791: rely on `zipfile.extractall` when extraxting ZIP archives, preventing false negatives and code dupli...

X Description: shutil.unpack_archive: deletage extracting ZIP files to zipfile (#111791) gh-111791: rely on `zipfile.extractall` when extraxting ZIP archives, preventing false negatives and code dupli...

Opengraph URL: https://github.com/python/cpython/pull/111824

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:2e37f2a3-8287-928b-555f-e9cfe46ba093
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD078:3A3C76:158B68D:1F61AE5:6A562031
html-safe-noncef0cc6e214b00c95b67d8d97295ed1a973f8c4fcf5bcf46b096b6d21651ffcee9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDc4OjNBM0M3NjoxNThCNjhEOjFGNjFBRTU6NkE1NjIwMzEiLCJ2aXNpdG9yX2lkIjoiNDQwNzQxMTI3MjQ2NTEyOTUyMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3974d2d0c2478dd8e5404837250fa407764e1a871941d2bf85bbccdfd3c2a3a7
hovercard-subject-tagpull_request:1590945877
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/python/cpython/pull/111824/files
twitter:imagehttps://avatars.githubusercontent.com/u/14915?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/14915?s=400&v=4
og:image:altshutil.unpack_archive: deletage extracting ZIP files to zipfile (#111791) gh-111791: rely on `zipfile.extractall` when extraxting ZIP archives, preventing false negatives and code dupli...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneeeb71977be324ce2bc7c4afd597296b8e3527d8922ad94632edd7a7296f8031b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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
release3e7957744c8a44d05ff1e464dc5d119e60b98fae
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/111824/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F111824%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%2Fpython%2Fcpython%2Fpull%2F111824%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=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/111824/files
Reloadhttps://github.com/python/cpython/pull/111824/files
Reloadhttps://github.com/python/cpython/pull/111824/files
Please reload this pagehttps://github.com/python/cpython/pull/111824/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/111824/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
sepastianhttps://github.com/sepastian
python:mainhttps://github.com/python/cpython/tree/main
sepastian:shutil_unpack_archive_false_positiveshttps://github.com/sepastian/cpython/tree/shutil_unpack_archive_false_positives
Conversation 13 https://github.com/python/cpython/pull/111824
Commits 10 https://github.com/python/cpython/pull/111824/commits
Checks 0 https://github.com/python/cpython/pull/111824/checks
Files changed https://github.com/python/cpython/pull/111824/files
Please reload this pagehttps://github.com/python/cpython/pull/111824/files
gh-111791: delegating extraction to zipfile module's extractall() method https://github.com/python/cpython/pull/111824/files#top
Show all changes 10 commits https://github.com/python/cpython/pull/111824/files
c8a6b24 fixing #111791: delegating extraction in shutil.unpack_archive to zip… sepastian Nov 7, 2023 https://github.com/python/cpython/pull/111824/commits/c8a6b2465c5f5c772b777252174a3338324539e6
7875a14 Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Nov 7, 2023 https://github.com/python/cpython/pull/111824/commits/7875a145910c5a4ba095e0e852077165c0ed9aa3
d50ea17 📜🤖 Added by blurb_it. blurb-it[bot] Nov 7, 2023 https://github.com/python/cpython/pull/111824/commits/d50ea17ab1b6f61484ca9869d61d98198568628b
9de81b1 Update shutil.rst sepastian Nov 7, 2023 https://github.com/python/cpython/pull/111824/commits/9de81b161e2f2e62070b736f29dc5a00c612077b
4ece8c1 Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Nov 8, 2023 https://github.com/python/cpython/pull/111824/commits/4ece8c17f1fef41e827dea00a6663bf8f2a59ed7
055e113 Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Nov 9, 2023 https://github.com/python/cpython/pull/111824/commits/055e113684cfa5126d2211619483012ccba3d72b
0f66cb3 Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Nov 22, 2023 https://github.com/python/cpython/pull/111824/commits/0f66cb3f5bb3517f6845033b550a8d35d66cb3f7
7f789f1 Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Dec 13, 2023 https://github.com/python/cpython/pull/111824/commits/7f789f195c0487749af96ca0d8d09a74b1806888
f090e3d Merge branch 'main' into shutil_unpack_archive_false_positives sepastian Feb 15, 2024 https://github.com/python/cpython/pull/111824/commits/f090e3db4a90b2c767c50b0952ac48f83531918e
0a18c01 Merge branch 'main' into shutil_unpack_archive_false_positives AlexWaygood Dec 9, 2024 https://github.com/python/cpython/pull/111824/commits/0a18c01fb278203c0f48207129987bf0b06e2a2c
Clear filters https://github.com/python/cpython/pull/111824/files
Please reload this pagehttps://github.com/python/cpython/pull/111824/files
Please reload this pagehttps://github.com/python/cpython/pull/111824/files
shutil.rst https://github.com/python/cpython/pull/111824/files#diff-f2e20586f33534d9cf4f058fffcedbe5cba1abf0f9e9813968846d7a8cccb719
shutil.py https://github.com/python/cpython/pull/111824/files#diff-db8ac59326160713929e0e1973aef54f0280fe9f154ef24d14244909a0e0689b
2023-11-07-17-08-09.gh-issue-111791.oJbxOQ.rst https://github.com/python/cpython/pull/111824/files#diff-24ca04969894014ba232897dcb2e2a66572b09940d262693e1d6a2ee67801b68
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L571
Doc/library/shutil.rsthttps://github.com/python/cpython/pull/111824/files#diff-f2e20586f33534d9cf4f058fffcedbe5cba1abf0f9e9813968846d7a8cccb719
View file https://github.com/sepastian/cpython/blob/0a18c01fb278203c0f48207129987bf0b06e2a2c/Doc/library/shutil.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/111824/{{ revealButtonHref }}
https://github.com/python/cpython/pull/111824/files#diff-f2e20586f33534d9cf4f058fffcedbe5cba1abf0f9e9813968846d7a8cccb719
https://github.com/python/cpython/pull/111824/files#diff-f2e20586f33534d9cf4f058fffcedbe5cba1abf0f9e9813968846d7a8cccb719
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L572
Lib/shutil.pyhttps://github.com/python/cpython/pull/111824/files#diff-db8ac59326160713929e0e1973aef54f0280fe9f154ef24d14244909a0e0689b
View file https://github.com/sepastian/cpython/blob/0a18c01fb278203c0f48207129987bf0b06e2a2c/Lib/shutil.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/111824/{{ revealButtonHref }}
https://github.com/python/cpython/pull/111824/files#diff-db8ac59326160713929e0e1973aef54f0280fe9f154ef24d14244909a0e0689b
https://github.com/python/cpython/pull/111824/files#diff-db8ac59326160713929e0e1973aef54f0280fe9f154ef24d14244909a0e0689b
Misc/NEWS.d/next/Library/2023-11-07-17-08-09.gh-issue-111791.oJbxOQ.rsthttps://github.com/python/cpython/pull/111824/files#diff-24ca04969894014ba232897dcb2e2a66572b09940d262693e1d6a2ee67801b68
View file https://github.com/sepastian/cpython/blob/0a18c01fb278203c0f48207129987bf0b06e2a2c/Misc/NEWS.d/next/Library/2023-11-07-17-08-09.gh-issue-111791.oJbxOQ.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/111824/{{ revealButtonHref }}
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.