Skip to content

Commit 67860c4

Browse files
committed
Add test to show all records in tar archive are extracted correctly with invalid PAX header 'size'
1 parent 1ed25f1 commit 67860c4

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎Lib/test/test_tarfile.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,32 @@ def test_pax_extended_header(self):
27592759
finally:
27602760
tar.close()
27612761

2762+
def test_invalid_size_pax_extended_header(self):
2763+
# When the value of the keyword 'size' is invalid, it should be
2764+
# ignored and proceeds to extract all the records instead of
2765+
# setting size to 0 and producing a single empty extracted file
2766+
t1sz = 89
2767+
t2sz = 64
2768+
with tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT,
2769+
pax_headers={"size": "xyz"},
2770+
encoding="iso8859-1") as tar:
2771+
t1 = tarfile.TarInfo()
2772+
t1.name = "foo"
2773+
t1.size = t1sz
2774+
tar.addfile(t1, io.BytesIO(b"a"*t1sz))
2775+
2776+
t2 = tarfile.TarInfo()
2777+
t2.name = "bar"
2778+
t2.size = t2sz
2779+
tar.addfile(t2, io.BytesIO(b"z"*t2sz))
2780+
2781+
t1_path = os.path.join(TEMPDIR, "foo")
2782+
t2_path = os.path.join(TEMPDIR, "bar")
2783+
with tarfile.open(tmpname, encoding="iso8859-1") as tar:
2784+
tar.extractall(path=TEMPDIR)
2785+
self.assertEqual(os.path.getsize(t1_path), t1sz)
2786+
self.assertEqual(os.path.getsize(t2_path), t2sz)
2787+
27622788
def test_create_pax_header(self):
27632789
# The ustar header should contain values that can be
27642790
# represented reasonably, even if a better (e.g. higher

0 commit comments

Comments
 (0)