Commit graph

237 commits

Author SHA1 Message Date
Jason R. Coombs
fc0b8259e6
[3.11] gh-123270: Replaced SanitizedNames with a more surgical fix. (GH-123354) (#123425)
Applies changes from zipp 3.20.1 and jaraco/zippGH-124
(cherry picked from commit 2231286d78)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>

* Restore the slash-prefixed paths in the malformed_paths test.
2024-09-04 17:52:54 +02:00
Jason R. Coombs
795f2597a4
[3.11] gh-122905: Sanitize names in zipfile.Path. (GH-122906) (#122925)
* gh-122905: Sanitize names in zipfile.Path. (#122906)

Ported from zipp 3.19.1; ref jaraco/zipp#119.

(cherry picked from commit 9cd0326310)

* [3.11] gh-122905: Sanitize names in zipfile.Path. (GH-122906)

Ported from zipp 3.19.1; ref jaraco/zippGH-119.
(cherry picked from commit 9cd0326310)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-08-20 00:28:20 +01:00
Serhiy Storchaka
0d82047645
[3.11] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162) (GH-117165)
(cherry picked from commit f3fee231d3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 567ab3bd15)
2024-03-22 19:24:27 +00:00
Miss Islington (bot)
a956e510f6
[3.11] gh-109858: Protect zipfile from "quoted-overlap" zipbomb (GH-110016) (GH-113913)
Raise BadZipFile when try to read an entry that overlaps with other entry or
central directory.
(cherry picked from commit 66363b9a7b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-01-11 11:24:47 +02:00
Jason R. Coombs
465f5b09df
[3.11] gh-106752: Sync with zipp 3.16.2 (GH-106757) (#106778)
* gh-106752: Sync with zipp 3.16.2 (#106757)

* gh-106752: Sync with zipp 3.16.2

* Add blurb

(cherry picked from commit 22980dc7c9)

* [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 22980dc7c9)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>

* Remove Python 3.12 concerns from changelog.
2023-07-15 10:15:38 -04:00
Gregory P. Smith
133bf0927e
[3.11] gh-103861: Fix Zip64 extensions not being properly applied in some 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 798bcaa1eb)

Co-authored-by: Carey Metcalfe <carey@cmetcalfe.ca>
2023-05-17 01:07:10 -07:00
Jason R. Coombs
d15e9589f3
[3.11] gh-101566: Sync with zipp 3.14. (GH-102018). (GH-102090)
(cherry picked from commit 36854bbb24)

Backport of bugfix only.

Automerge-Triggered-By: GH:jaraco
2023-02-20 15:22:03 -08:00
Miss Islington (bot)
62c0327487
gh-88233: zipfile: handle extras after a zip64 extra (GH-96161)
Previously, any data _after_ the zip64 extra would be removed.

With many new tests.

Fixes GH-88233
(cherry picked from commit 59e86caca8)

Co-authored-by: Tim Hatch <tim@timhatch.com>
Automerge-Triggered-By: GH:jaraco
2023-02-20 09:33:00 -08:00
Gregory P. Smith
efe3a389ca
[3.11] gh-101144: Allow zipfile.Path .open & .read_text encoding to be 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 5927013e47)

Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google]
2023-01-20 00:06:18 -08:00
Miss Islington (bot)
7a84ce5c44
gh-95463: Remove backwards incompatible change regarding the _MASK_UTF_FILENAME flags in bpo-28080 (GH-96072)
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 9d066e2aa6)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-08-18 17:12:15 -07:00
Miss Islington (bot)
e9d6ca4334
[3.11] gh-83245: Raise BadZipFile instead of ValueError when reading a corrupt ZIP file (GH-32291) (GH-93141)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 202ed2506c)


Co-authored-by: Sam Ezeh <sam.z.ezeh@gmail.com>

Automerge-Triggered-By: GH:serhiy-storchaka
2022-05-25 00:57:36 -07:00
Sam Ezeh
050a8f94c6
bpo-4833: Add ZipFile.mkdir (GH-32160) 2022-04-05 11:41:38 -07:00
Serhiy Storchaka
a25a985535
bpo-28080: Add support for the fallback encoding in ZIP files (GH-32007)
* 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>
2022-03-22 11:52:55 +02:00
Kevin Mehall
e730ae7eff
bpo-42369: Fix thread safety of zipfile._SharedFile.tell (GH-26974)
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.
2022-03-20 16:26:09 +02:00
Ma Lin
36dd7396fc
bpo-44439: _ZipWriteFile.write() handle buffer protocol correctly (GH-29468)
Co-authored-by: Marco Ribeiro <marcoffee@users.noreply.github.com>
2022-03-08 11:33:56 +02:00
Daniel Hillier
91099e2544
bpo-39359: [zipfile] add missing "pwd: expected bytes, got str" exception (GH-18031) 2021-09-23 23:37:53 +02:00
Daniel Hillier
556d5ad11f
bpo-44129: Add descriptive global variables for general purpose bit flags (GH-26118)
Replace hex flag masks with named global variables to improve
readability.

eg.
    if flags & 0x800
becomes:
    if flags & _MASK_UTF_FILENAME
2021-07-03 17:37:57 +03:00
Miguel Brito
dc0b364de4
bpo-44095: Add suffix, stem and suffixes to zipfile.Path (GH-26129) 2021-05-14 10:57:36 -07:00
Inada Naoki
caae717c29
bpo-43651: Fix EncodingWarning in zipfile (GH-25650) 2021-04-27 15:45:31 +09:00
Jason R. Coombs
928dbfc16c
bpo-42090: zipfile.Path.joinpath now accepts multiple arguments (GH-22976)
Automerge-Triggered-By: GH:jaraco
2020-12-15 18:12:54 -08:00
Jason R. Coombs
d1a0a960ee
bpo-42043: Add support for zipfile.Path subclasses (#22716)
* bpo-42043: Add support for zipfile.Path inheritance as introduced in zipp 3.2.0.

* Add blurb.
2020-10-25 14:45:05 -04:00
Jason R. Coombs
ebbe8033b1
bpo-40564: Avoid copying state from extant ZipFile. (GH-22371)
bpo-40564: Avoid copying state from extant ZipFile.
2020-10-03 10:58:39 -04:00
Jan Mazur
ff9147d93b
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337) 2020-09-28 21:53:33 +03:00
Serhiy Storchaka
36ff513f82
bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040) 2020-06-22 11:24:11 +03:00
Victor Stinner
90549676e0
bpo-40443: Remove unused imports in the stdlib (GH-19803) 2020-04-30 11:26:33 +02:00
Zackery Spytz
9a81ab107a
bpo-39830: Add zipfile.Path to __all__ (GH-19115) 2020-03-23 09:29:36 -04:00
Jason R. Coombs
0aeab5c438
bpo-39667: Sync zipp 3.0 (GH-18540)
* 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>
2020-02-29 10:34:11 -06:00
Jason R. Coombs
e5bd73632e
bpo-39595: Improve zipfile.Path performance (#18406)
* 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>
2020-02-11 21:58:47 -05:00
Victor Stinner
1d3b0aaa54
bpo-39356, zipfile: Remove code handling DeprecationWarning (GH-18027)
Remove old "except DeprecationWarning:" code path added by
commit bf02e3bb21. 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.
2020-01-17 15:17:48 +01:00
Daniel Hillier
8d62df60d8 bpo-37523: Raise ValueError for I/O operations on a closed zipfile.ZipExtFile. (GH-14658)
Raises ValueError when calling the following on a closed zipfile.ZipExtFile: read, readable, seek, seekable, tell.
2019-11-30 10:30:47 +02:00
Serhiy Storchaka
e27449da92
bpo-38635: Simplify decoding the ZIP64 extra field and make it tolerant to extra data. (GH-16988) 2019-11-09 13:13:36 +02:00
Daniel Hillier
da6ce58dd5 bpo-36993: Improve error reporting for zipfiles with bad zip64 extra data. (GH-14656) 2019-10-29 09:24:18 +02:00
Serhiy Storchaka
5c32af7522
bpo-38334: Fix seeking backward on an encrypted zipfile.ZipExtFile. (GH-16937)
Test by Daniel Hillier.
2019-10-27 10:22:14 +02:00
Berker Peksag
2f1b857562 bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632) 2019-09-12 15:13:44 +01:00
Mickaël Schoentgen
992347d737 bpo-26185: Fix repr() on empty ZipInfo object (#13441)
* 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().
2019-09-09 06:08:54 -07:00
shireenrao
a4e2991bdc bpo-37772: fix zipfile.Path.iterdir() outputs (GH-15170)
* 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.
2019-08-24 11:26:41 -04:00
Jason R. Coombs
38f44b4a4a
bpo-37520: Correct behavior for zipfile.Path.parent (GH-14638)
* bpo-37520: Correct behavior for zipfile.Path.parent

* 📜🤖 Added by blurb_it.
2019-07-07 17:37:50 -04:00
Xtreak
0d70227e41 Fix typos in docs and docstrings (GH-13745) 2019-06-03 01:12:33 +02:00
Francisco Facioni
ab0716ed1e bpo-22102: Fixes zip files with disks set to 0 (GH-5985) 2019-05-28 19:15:11 -04:00
Jason R. Coombs
33e067d6a2 Add support for .parent and .joinpath in zipfile.Path (#13213) 2019-05-09 11:34:35 -04:00
Jason R. Coombs
b2758ff955 bpo-36832: add zipfile.Path (#13153)
* 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
2019-05-08 09:45:05 -04:00
Serhiy Storchaka
2524fdefc9
bpo-36434: Properly handle writing errors in ZIP files. (GH-12559)
Errors during writing no longer prevent to properly close
the ZIP file.
2019-03-30 08:25:19 +02:00
nick sung
53c2935dac Fix typo duplicate period in a docstring in the zipfile module. (GH-12326) 2019-03-14 21:26:25 +02:00
Serhiy Storchaka
4bb186d7e2
bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592) 2018-11-25 09:51:14 +02:00
Silas Sewell
4ba3b50bfe bpo-34472: Add data descriptor signature to zipfile (GH-8871)
This makes streamed zips compatible with MacOS Archive Utility and
other applications.
2018-09-18 20:00:05 +03:00
Serhiy Storchaka
9bdb7be482
bpo-34341: Fix appending to ZIP archives with the ZIP64 extension. (GH-8683) 2018-09-17 15:36:40 +03:00
Marcel Plch
77b112cd56 bpo-34097: Polish API design (GH-8725)
Move strict_timestamps to constructor.
2018-08-31 16:43:31 +02:00
Marcel Plch
a2fe1e52eb bpo-34097: Add support for zipping files older than 1980-01-01 (GH-8270)
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.
2018-08-02 15:04:52 +02:00
Mickaël Schoentgen
3f8c6913b8 bpo-34035: Fix several AttributeError in zipfile seek() methods. (GH-8527) 2018-07-29 21:26:52 +03:00
Bernhard M. Wiedemann
84521047e4 bpo-30693: zip+tarfile: sort directory listing (#2263)
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.
2018-01-31 11:17:10 +01:00