Commit Graph

204 Commits

Author SHA1 Message Date
Sam Ezeh 78365b8e28
gh-91078: Return None from TarFile.next when the tarfile is empty (GH-91850)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-11-26 09:57:05 -08:00
Christian Heimes b528499052
gh-70441: Fix test_tarfile on systems w/o bz2 (gh-2962) (#94258) 2022-06-25 12:53:37 +02:00
Yaron de Leeuw 50cd4b6959
bpo-26253: Add compressionlevel to tarfile stream (GH-2962)
`tarfile` already accepts a compressionlevel argument for creating
files. This patch adds the same for stream-based tarfile usage.
The default is 9, the value that was previously hard-coded.
2022-06-25 11:43:54 +03:00
Christian Heimes dd78aae34b
gh-91387: Fix tarfile test on WASI (GH-93984)
WASI's rmdir() syscall does not like the trailing slash.
2022-06-18 10:55:48 -07:00
Chris Fernald c1e19421c2
gh-91387: Strip trailing slash from tarfile longname directories (GH-32423)
Co-authored-by: Brett Cannon <brett@python.org>
2022-06-17 15:38:41 -07:00
Christian Heimes 22fed605e0
gh-90473: Make chmod a dummy on WASI, skip chmod tests (GH-93534)
WASI does not have the ``chmod(2)`` syscall yet.
2022-06-06 19:24:11 +02:00
Christian Heimes 1f134e96ba
gh-90473: Misc test fixes for WASI (GH-93218)
* ``sys.executable`` is not set
* WASI does not support subprocess
* ``pwd`` module is not available
* WASI checks ``open`` syscall flags more strict, needs r, w, rw flag.
* ``umask`` is not available
* ``/dev/null`` may not be accessible
2022-05-25 15:57:26 +02:00
Christian Heimes de554d6e02
bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-31791)
- fd inheritance can't be modified because Emscripten doesn't support subprocesses anyway.
- setpriority always fails
- geteuid no longer causes problems with latest emsdk
- umask is a stub
- geteuid / getuid always return 0, but process cannot chown to random uid.
2022-03-10 13:43:40 +01:00
Joshua Root bf2d44ffb0
bpo-45863: tarfile: don't zero out header fields unnecessarily (GH-29693)
Numeric fields of type float, notably mtime, can't be represented
exactly in the ustar header, so the pax header is used. But it is
helpful to set them to the nearest int (i.e. second rather than
nanosecond precision mtimes) in the ustar header as well, for the
benefit of unarchivers that don't understand the pax header.

Add test for tarfile.TarInfo.create_pax_header to confirm correct
behaviour.
2022-02-09 18:06:19 +01:00
Andrzej Mateja 128ab092ca
bpo-44289: Keep argument file object's current position in tarfile.is_tarfile (GH-26488) 2022-02-09 08:19:16 -08:00
andrei kulakov cfadcc31ea
bpo-21987: Fix TarFile.getmember getting a dir with a trailing slash (GH-30283) 2022-01-21 09:40:32 +02:00
Jack DeVries b6fe857250
bpo-39039: tarfile raises descriptive exception from zlib.error (GH-27766)
* during tarfile parsing, a zlib error indicates invalid data
* tarfile.open now raises a descriptive exception from the zlib error
* this makes it clear to the user that they may be trying to open a
  corrupted tar file
2021-09-29 11:25:48 +02:00
Zackery Spytz eb2d4a66ff
bpo-32695: Docs and tests for compresslevel and preset kwargs in tarfile (GH-21470)
Co-Authored-By: Bo Bayles <bbayles@gmail.com>
2021-08-09 12:05:31 +02:00
Anthony Sottile 9aea31dedd
bpo-8978: improve tarfile.open error message when lzma / bz2 are missing (GH-24850)
Automerge-Triggered-By: GH:pablogsal
2021-04-27 10:39:01 -07:00
Julien Palard 4fedd7123e
bpo-12800: tarfile: Restore fix from 011525ee9 (GH-21409)
Restore fix from 011525ee92.
2020-11-25 10:23:17 +01:00
Artem Bulgakov 22748a83d9
bpo-41316: Make tarfile follow specs for FNAME (GH-21511)
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
2020-09-07 09:46:33 -07:00
Victor Stinner fbf43f051e
bpo-41521: Rename blacklist parameter to not_exported (GH-21824)
Rename "blacklist" parameter of test.support.check__all__() to
"not_exported".
2020-08-17 07:20:40 +02:00
Hai Shi a7f5d93bb6
bpo-40275: Use new test.support helper submodules in tests (GH-21449) 2020-08-03 18:41:24 +02:00
Rishi 5a8d121a1f
bpo-39017: Avoid infinite loop in the tarfile module (GH-21454)
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
2020-07-15 13:51:00 +02:00
Serhiy Storchaka 700cfa8c90
bpo-41069: Make TESTFN and the CWD for tests containing non-ascii characters. (GH-21035) 2020-06-25 17:56:31 +03:00
Hai Shi a3ec3ad9e2
bpo-40275: More lazy imports in test.support (GH-20131)
Make the the following imports lazy in test.support:

* bz2
* gzip
* lzma
* resource
* zlib

The following test.support decorators now need to be called
with parenthesis:

* @support.requires_bz2
* @support.requires_gzip
* @support.requires_lzma
* @support.requires_zlib

For example, "@requires_zlib" becomes "@requires_zlib()".
2020-05-19 00:02:57 +02:00
Hai Shi 66abe98a81
bpo-40275: Move requires_hashdigest() to test.support.hashlib_helper (GH-19716)
Add a new test.support.hashlib_helper submodule.
2020-04-29 03:11:29 +02:00
Victor Stinner 87502ddd71
bpo-40286: Use random.randbytes() in tests (GH-19575) 2020-04-17 22:54:38 +02:00
William Chargin 674935b8ca
bpo-18819: tarfile: only set device fields for device files (GH-18080)
The GNU docs describe the `devmajor` and `devminor` fields of the tar
header struct only in the context of character and block special files,
suggesting that in other cases they are not populated. Typical utilities
behave accordingly; this patch teaches `tarfile` to do the same.
2020-02-12 11:56:02 -08:00
William Woodruff dd754caf14 bpo-29435: Allow is_tarfile to take a filelike obj (GH-18090)
`is_tarfile()` now supports `name` being a file or file-like object.
2020-01-22 18:24:16 -08:00
Christian Heimes c64a1a61e6 bpo-38270: Check for hash digest algorithms and avoid MD5 (GH-16382)
Make it easier to run and test Python on systems with restrict crypto policies:

* add requires_hashdigest to test.support to check if a hash digest algorithm is available and working
* avoid MD5 in test_hmac
* replace MD5 with SHA256 in test_tarfile
* mark network tests that require MD5 for MD5-based digest auth or CRAM-MD5


https://bugs.python.org/issue38270
2019-09-25 07:30:20 -07:00
CAM Gerlach e680c3db80 bpo-36268: Change default tar format to pax from GNU. (GH-12355) 2019-03-21 16:44:51 +02:00
Serhiy Storchaka 9e4861f523
bpo-22831: Use "with" to avoid possible fd leaks in tests (part 1). (GH-10928) 2019-03-05 10:05:57 +02:00
Victor Stinner b2385458ce
bpo-35772: Fix test_tarfile on ppc64 (GH-11606)
Fix sparse file tests of test_tarfile on ppc64le with the tmpfs
filesystem.

Fix the function testing if the filesystem supports sparse files:
create a file which contains data and "holes", instead of creating a
file which contains no data.

tmpfs effective block size is a page size (tmpfs lives in the page
cache). RHEL uses 64 KiB pages on aarch64, ppc64 and ppc64le, only
s390x and x86_64 use 4 KiB pages, whereas the test punch holes of
4 KiB.

test.pythoninfo: Add resource.getpagesize().
2019-01-21 10:24:12 +01:00
Joffrey F 72d9b2be36 bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434) 2018-02-27 02:02:21 +02:00
Bernhard M. Wiedemann 4ad703b7ca bpo-30693: Fix tarfile test cleanup on MSWindows (#5557)
it was using our mocked listdir to check when the files were gone.
2018-02-06 20:08:53 +02: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
xdegaye d7d4fea4a3
bpo-29181: Skip test_tarfile tests on PermissionError raised by Android (GH-4375) 2017-11-12 18:02:06 +01:00
Victor Stinner 8c663fd60e
Replace KB unit with KiB (#4293)
kB (*kilo* byte) unit means 1000 bytes, whereas KiB ("kibibyte")
means 1024 bytes. KB was misused: replace kB or KB with KiB when
appropriate.

Same change for MB and GB which become MiB and GiB.

Change the output of Tools/iobench/iobench.py.

Round also the size of the documentation from 5.5 MB to 5 MiB.
2017-11-08 14:44:44 -08:00
Serhiy Storchaka 150cd1916a bpo-29958: Minor improvements to zipfile and tarfile CLI. (#944) 2017-04-07 18:56:12 +03:00
Serhiy Storchaka c45cd167d4 bpo-28230: Document the pathlib support in tarfile and add tests. (#512) 2017-03-08 10:32:44 +02:00
Serhiy Storchaka 4f76fb16b7 Issue #29210: Removed support of deprecated argument "exclude" in
tarfile.TarFile.add().
2017-01-13 13:25:24 +02:00
Serhiy Storchaka 2f4453eff8 Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
file with compression before trying to open it without compression.  Otherwise
it had 50% chance failed with ignore_zeros=True.
2016-10-30 20:56:23 +02:00
Serhiy Storchaka a89d22aff3 Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
file with compression before trying to open it without compression.  Otherwise
it had 50% chance failed with ignore_zeros=True.
2016-10-30 20:52:29 +02:00
Lars Gustäbel daac5f9f92 Issue #24838: Merge test_tarfile.py fix from 3.5. 2016-04-19 11:59:39 +02:00
Lars Gustäbel ddd9917ac3 Issue #24838: Fix test_tarfile.py for non-utf8 filesystem encodings. 2016-04-19 11:58:41 +02:00
Lars Gustäbel 7c3e6848f2 Issue #24838: Merge tarfile fix from 3.5. 2016-04-19 08:53:14 +02:00
Lars Gustäbel 0f450abec4 Issue #24838: tarfile's ustar and gnu formats now correctly calculate name and
link field limits for multibyte character encodings like utf-8.
2016-04-19 08:43:17 +02:00
Martin Panter 5318d1048f Issue #23883: grp and pwd are None on Windows 2016-01-16 11:01:14 +00:00
Serhiy Storchaka 2c1d3e320f Issue #23883: Removed redundant names from blacklists. 2016-01-16 11:05:11 +02:00
Martin Panter 104dcdab59 Issue #23883: Add missing APIs to tarfile.__all__
Patch by Joel Taddei and Jacek Kołodziej.
2016-01-16 06:59:13 +00:00
Serhiy Storchaka 5fbadb63ef Use support.change_cwd() in tests. 2015-09-06 14:14:49 +03:00
Serhiy Storchaka 2a23adf440 Use support.change_cwd() in tests. 2015-09-06 14:13:25 +03:00
Lars Gustäbel e12aa62d68 Merge with 3.4: Issue #24259: tarfile now raises a ReadError if an archive is truncated inside a data segment. 2015-07-06 09:29:41 +02:00
Lars Gustäbel 0357268d96 Issue #24259: tarfile now raises a ReadError if an archive is truncated inside a data segment. 2015-07-06 09:27:24 +02:00