summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-109858: Protect zipfile from "quoted-overlap" zipbomb (GH-110016) ↵Miss Islington (bot)2024-01-111-0/+12
| | | | | | | | | (GH-113913) Raise BadZipFile when try to read an entry that overlaps with other entry or central directory. (cherry picked from commit 66363b9a7b9fe7c99eba3a185b74c5fdbf842eba) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) (#106778)Jason R. Coombs2023-07-151-4/+7
| | | | | | | | | | | | | | | | | | | | * gh-106752: Sync with zipp 3.16.2 (#106757) * gh-106752: Sync with zipp 3.16.2 * Add blurb (cherry picked from commit 22980dc7c9dcec4b74fea815542601ef582c230e) * [3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) * gh-106752: Sync with zipp 3.16.2 * Add blurb. (cherry picked from commit 22980dc7c9dcec4b74fea815542601ef582c230e) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> * Remove Python 3.12 concerns from changelog.
* [3.11] gh-103861: Fix Zip64 extensions not being properly applied in some ↵Gregory P. Smith2023-05-171-15/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cases (GH-103863) (#104534) Fix Zip64 extensions not being properly applied in some cases: Fixes an issue where adding a small file to a `ZipFile` object while forcing zip64 extensions causes an extra Zip64 record to be added to the zip, but doesn't update the `min_version` or file sizes in the primary central directory header. Also fixed an edge case in checking if zip64 extensions are required: This fixes an issue where if data requiring zip64 extensions was added to an unseekable stream without specifying `force_zip64=True`, zip64 extensions would not be used and a RuntimeError would not be raised when closing the file (even though the size would be known at that point). This would result in successfully writing corrupt zip files. Deciding if zip64 extensions are required outside of the `FileHeader` function means that both `FileHeader` and `_ZipWriteFile` will always be in sync. Previously, the `FileHeader` function could enable zip64 extensions without propagating that decision to the `_ZipWriteFile` class, which would then not correctly write the data descriptor record or check for errors on close. If anyone is actually using `ZipInfo.FileHeader` as a public API without explicitly passing True or False in for zip64, their own code may still be susceptible to that kind of bug unless they make a similar change to where the zip64 decision happens. Fixes GH-103861 --------- . (cherry picked from commit 798bcaa1eb01de7db9ff1881a3088603ad09b096) Co-authored-by: Carey Metcalfe <carey@cmetcalfe.ca>
* [3.11] gh-101566: Sync with zipp 3.14. (GH-102018). (GH-102090)Jason R. Coombs2023-02-201-0/+11
| | | | | | | (cherry picked from commit 36854bbb240e417c0df6f0014924fcc899388186) Backport of bugfix only. Automerge-Triggered-By: GH:jaraco
* gh-88233: zipfile: handle extras after a zip64 extra (GH-96161)Miss Islington (bot)2023-02-201-0/+2
| | | | | | | | | | | Previously, any data _after_ the zip64 extra would be removed. With many new tests. Fixes GH-88233 (cherry picked from commit 59e86caca812fc993c5eb7dc8ccd1508ffccba86) Co-authored-by: Tim Hatch <tim@timhatch.com> Automerge-Triggered-By: GH:jaraco
* [3.11] gh-101144: Allow zipfile.Path .open & .read_text encoding to be ↵Gregory P. Smith2023-01-201-5/+10
| | | | | | | | | | | positional (#101179) The zipfile.Path open() and read_text() encoding parameter can be supplied as a positional argument without causing a TypeError again. 3.10.0b1 included a regression that made it keyword only. Documentation update included as users writing code to be compatible with a wide range of versions will need to consider this for some time.. (cherry picked from commit 5927013e47a8c63b70e104152351f3447baa819c) Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google]
* gh-95463: Remove backwards incompatible change regarding the ↵Miss Islington (bot)2022-08-191-1/+1
| | | | | | | | _MASK_UTF_FILENAME flags in bpo-28080 (GH-96072) Automerge-Triggered-By: GH:pablogsal (cherry picked from commit 9d066e2aa621125cd141b14df79955d74b7f258e) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.11] gh-83245: Raise BadZipFile instead of ValueError when reading a ↵Miss Islington (bot)2022-05-251-0/+2
| | | | | | | | | | | corrupt ZIP file (GH-32291) (GH-93141) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit 202ed2506c84cd98e9e35621b5b2929ceb717864) Co-authored-by: Sam Ezeh <sam.z.ezeh@gmail.com> Automerge-Triggered-By: GH:serhiy-storchaka
* bpo-4833: Add ZipFile.mkdir (GH-32160)Sam Ezeh2022-04-051-17/+36
|
* bpo-28080: Add support for the fallback encoding in ZIP files (GH-32007)Serhiy Storchaka2022-03-221-8/+23
| | | | | | * Add the metadata_encoding parameter in the zipfile.ZipFile constructor. * Add the --metadata-encoding option in the zipfile CLI. Co-authored-by: Stephen J. Turnbull <stephen@xemacs.org>
* bpo-42369: Fix thread safety of zipfile._SharedFile.tell (GH-26974)Kevin Mehall2022-03-201-1/+3
| | | | | | | | | | | The `_SharedFile` tracks its own virtual position into the file as `self._pos` and updates it after reading or seeking. `tell()` should return this position instead of calling into the underlying file object, since if multiple `_SharedFile` instances are being used concurrently on the same file, another one may have moved the real file position. Additionally, calling into the underlying `tell` may expose thread safety issues in the underlying file object because it was called without taking the lock.
* bpo-44439: _ZipWriteFile.write() handle buffer protocol correctly (GH-29468)Ma Lin2022-03-081-1/+8
| | | | Co-authored-by: Marco Ribeiro <marcoffee@users.noreply.github.com>
* bpo-39359: [zipfile] add missing "pwd: expected bytes, got str" exception ↵Daniel Hillier2021-09-231-2/+2
| | | | (GH-18031)
* bpo-44129: Add descriptive global variables for general purpose bit flags ↵Daniel Hillier2021-07-031-12/+38
| | | | | | | | | | | (GH-26118) Replace hex flag masks with named global variables to improve readability. eg. if flags & 0x800 becomes: if flags & _MASK_UTF_FILENAME
* bpo-44095: Add suffix, stem and suffixes to zipfile.Path (GH-26129)Miguel Brito2021-05-141-0/+12
|
* bpo-43651: Fix EncodingWarning in zipfile (GH-25650)Inada Naoki2021-04-271-0/+3
|
* bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)Jason R. Coombs2020-12-161-2/+2
| | | Automerge-Triggered-By: GH:jaraco
* bpo-42043: Add support for zipfile.Path subclasses (#22716)Jason R. Coombs2020-10-251-9/+30
| | | | | * bpo-42043: Add support for zipfile.Path inheritance as introduced in zipp 3.2.0. * Add blurb.
* bpo-40564: Avoid copying state from extant ZipFile. (GH-22371)Jason R. Coombs2020-10-031-6/+17
| | | bpo-40564: Avoid copying state from extant ZipFile.
* bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)Jan Mazur2020-09-281-0/+2
|
* bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040)Serhiy Storchaka2020-06-221-1/+1
|
* bpo-40443: Remove unused imports in the stdlib (GH-19803)Victor Stinner2020-04-301-1/+0
|
* bpo-39830: Add zipfile.Path to __all__ (GH-19115)Zackery Spytz2020-03-231-1/+2
|
* bpo-39667: Sync zipp 3.0 (GH-18540)Jason R. Coombs2020-02-291-32/+31
| | | | | | | | | | | | | | * bpo-39667: Improve pathlib.Path compatibility on zipfile.Path and correct performance degradation as found in zipp 3.0 * 📜🤖 Added by blurb_it. * Update docs for new zipfile.Path.open * Rely on dict, faster than OrderedDict. * Syntax edits on docs Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-39595: Improve zipfile.Path performance (#18406)Jason R. Coombs2020-02-121-22/+80
| | | | | | | | | | | | | | | | | | * Improve zipfile.Path performance on zipfiles with a large number of entries. * 📜🤖 Added by blurb_it. * Add bpo to blurb * Sync with importlib_metadata 1.5 (6fe70ca) * Update blurb. * Remove compatibility code * Add stubs module, omitted from earlier commit Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-39356, zipfile: Remove code handling DeprecationWarning (GH-18027)Victor Stinner2020-01-171-19/+9
| | | | | | | | Remove old "except DeprecationWarning:" code path added by commit bf02e3bb21b2d75cba4ce409a14ae64dbc2dd6d2. It's no longer needed. struct.pack() no longer emit DeprecationWarning if getting a float whereas an integer is expected. It now raises an hard error instead.
* bpo-37523: Raise ValueError for I/O operations on a closed ↵Daniel Hillier2019-11-301-0/+10
| | | | | zipfile.ZipExtFile. (GH-14658) Raises ValueError when calling the following on a closed zipfile.ZipExtFile: read, readable, seek, seekable, tell.
* bpo-38635: Simplify decoding the ZIP64 extra field and make it tolerant to ↵Serhiy Storchaka2019-11-091-37/+16
| | | | extra data. (GH-16988)
* bpo-36993: Improve error reporting for zipfiles with bad zip64 extra data. ↵Daniel Hillier2019-10-291-0/+12
| | | | (GH-14656)
* bpo-38334: Fix seeking backward on an encrypted zipfile.ZipExtFile. (GH-16937)Serhiy Storchaka2019-10-271-26/+31
| | | Test by Daniel Hillier.
* bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)Berker Peksag2019-09-121-0/+1
|
* bpo-26185: Fix repr() on empty ZipInfo object (#13441)Mickaël Schoentgen2019-09-091-5/+3
| | | | | | | | | | | | * bpo-26185: Fix repr() on empty ZipInfo object It was failing on AttributeError due to inexistant but required attributes file_size and compress_size. They are now initialized to 0 in ZipInfo.__init__(). * Remove useless hasattr() in ZipInfo._open_to_write() * Completely remove file_size setting in _open_to_write().
* bpo-37772: fix zipfile.Path.iterdir() outputs (GH-15170)shireenrao2019-08-241-6/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fix Path._add_implied_dirs to include all implied directories * fix Path._add_implied_dirs to include all implied directories * Optimize code by using sets instead of lists * 📜🤖 Added by blurb_it. * fix Path._add_implied_dirs to include all implied directories * Optimize code by using sets instead of lists * 📜🤖 Added by blurb_it. * Add tests to zipfile.Path.iterdir() fix * Update test for zipfile.Path.iterdir() * remove whitespace from test file * Rewrite NEWS blurb to describe the user-facing impact and avoid implementation details. * remove redundant [] within set comprehension * Update to use unique_everseen to maintain order and other suggestions in review * remove whitespace and add back add_dirs in tests * Add new standalone function parents using posixpath to get parents of a directory * removing whitespace (sorry) * Remove import pathlib from zipfile.py * Rewrite _parents as a slice on a generator of the ancestry of a path. * Remove check for '.' and '/', now that parents no longer returns those. * Separate calculation of implied dirs from adding those * Re-use _implied_dirs in tests for generating zipfile with dir entries. * Replace three fixtures (abcde, abcdef, abde) with one representative example alpharep. * Simplify implementation of _implied_dirs by collapsing the generation of parent directories for each name.
* bpo-37520: Correct behavior for zipfile.Path.parent (GH-14638)Jason R. Coombs2019-07-071-1/+1
| | | | | | * bpo-37520: Correct behavior for zipfile.Path.parent * 📜🤖 Added by blurb_it.
* Fix typos in docs and docstrings (GH-13745)Xtreak2019-06-021-1/+1
|
* bpo-22102: Fixes zip files with disks set to 0 (GH-5985)Francisco Facioni2019-05-281-1/+1
|
* Add support for .parent and .joinpath in zipfile.Path (#13213)Jason R. Coombs2019-05-091-1/+10
|
* bpo-36832: add zipfile.Path (#13153)Jason R. Coombs2019-05-081-5/+139
| | | | | | | | | | | | | | | | | | | | | | | | * bpo-36832: add zipfile.Path * bpo-36832: add documentation for zipfile.Path * 📜🤖 Added by blurb_it. * Remove module reference from blurb. * Sort the imports * Update docstrings and docs per recommendations. * Rely on test.support.temp_dir * Signal that 'root' is the parameter. * Correct spelling of 'mod' * Convert docstring to comment for brevity. * Fix more errors in the docs
* bpo-36434: Properly handle writing errors in ZIP files. (GH-12559)Serhiy Storchaka2019-03-301-41/+44
| | | | | Errors during writing no longer prevent to properly close the ZIP file.
* Fix typo duplicate period in a docstring in the zipfile module. (GH-12326)nick sung2019-03-141-1/+1
|
* bpo-32035: Fix words about strings and bytes in zipfile documentation. ↵Serhiy Storchaka2018-11-251-2/+2
| | | | (GH-10592)
* bpo-34472: Add data descriptor signature to zipfile (GH-8871)Silas Sewell2018-09-181-2/+4
| | | | This makes streamed zips compatible with MacOS Archive Utility and other applications.
* bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683)Serhiy Storchaka2018-09-171-0/+22
|
* bpo-34097: Polish API design (GH-8725)Marcel Plch2018-08-311-4/+4
| | | Move strict_timestamps to constructor.
* bpo-34097: Add support for zipping files older than 1980-01-01 (GH-8270)Marcel Plch2018-08-021-3/+9
| | | | | ZipFile can zip files older than 1980-01-01 and newer than 2107-12-31 using a new strict_timestamps parameter at the cost of setting the timestamp to the limit.
* bpo-34035: Fix several AttributeError in zipfile seek() methods. (GH-8527)Mickaël Schoentgen2018-07-291-4/+3
|
* bpo-30693: zip+tarfile: sort directory listing (#2263)Bernhard M. Wiedemann2018-01-311-3/+3
| | | | | | tarfile and zipfile now sort directory listing to generate tar and zip archives in a more reproducible way. See also https://reproducible-builds.org/docs/stable-inputs/ on that topic.
* bpo-22908: Add seek and tell functionality to ZipExtFile (GH-4966)John Jolly2018-01-301-0/+82
| | | | | This allows for nested zip files, tar files within zip files, zip files within tar files, etc. Contributed by: John Jolly
* bpo-21417: Add compresslevel= to the zipfile module (GH-5385)Bo Bayles2018-01-301-8/+35
| | | | | | This allows the compression level to be specified when writing zipfiles (for the entire file *and* overridden on a per-file basis). Contributed by Bo Bayles
* bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou2017-09-071-5/+1
| | | | | | * Remove Setup.config * Always define WITH_THREAD for compatibility.