Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-43650: Fix MemoryError on zip.read in shutil._unpack_zipfile for large files #25058

Merged
merged 3 commits into from
May 17, 2021

Conversation

igorvoltaic
Copy link
Contributor

@igorvoltaic igorvoltaic commented Mar 28, 2021

shutil.unpack_archive() tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form zipfile.Zipfile.extractall() to fix this

https://bugs.python.org/issue43650

Automerge-Triggered-By: GH:gpshead

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@igorvoltaic

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@igorvoltaic
Copy link
Contributor Author

Still relevant

@gpshead gpshead added needs backport to 3.10 only security fixes needs backport to 3.9 only security fixes type-bug An unexpected behavior, bug, or error 🤖 automerge labels May 17, 2021
@miss-islington
Copy link
Contributor

@igorvoltaic: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit f32c795 into python:main May 17, 2021
@miss-islington
Copy link
Contributor

Thanks @igorvoltaic for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-26190 is a backport of this pull request to the 3.10 branch.

@bedevere-bot
Copy link

GH-26191 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 17, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 17, 2021
…large files (pythonGH-25058)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 17, 2021
…large files (pythonGH-25058)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
@ghost
Copy link

ghost commented May 17, 2021

If copyfileobj() raises an exception, target will not be closed?

Sorry, it's not true.

@igorvoltaic igorvoltaic deleted the fix-issue-43650 branch May 17, 2021 10:37
miss-islington added a commit that referenced this pull request May 17, 2021
…large files (GH-25058)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
gpshead pushed a commit that referenced this pull request May 17, 2021
…large files (GH-25058) (GH-26190)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
@gpshead
Copy link
Member

gpshead commented May 17, 2021

good thing to look for. thankfully the with statement context manager closes both on the way out.

gentoo-bot pushed a commit to gentoo/cpython that referenced this pull request May 21, 2024
…large files (pythonGH-25058)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
gentoo-bot pushed a commit to gentoo/cpython that referenced this pull request Sep 19, 2024
…large files (pythonGH-25058)

`shutil.unpack_archive()` tries to read the whole file into memory, making no use of any kind of smaller buffer. Process crashes for really large files: I.e. archive: ~1.7G, unpacked: ~10G. Before the crash it can easily take away all available RAM on smaller systems. Had to pull the code form `zipfile.Zipfile.extractall()` to fix this

Automerge-Triggered-By: GH:gpshead
(cherry picked from commit f32c795)

Co-authored-by: Igor Bolshakov <ibolsch@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants