MCPcopy Index your code
hub / github.com/python/cpython / test_premature_end_of_archive

Method test_premature_end_of_archive

Lib/test/test_tarfile.py:495–517  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

493 tar.close()
494
495 def test_premature_end_of_archive(self):
496 for size in (512, 600, 1024, 1200):
497 with tarfile.open(tmpname, "w:") as tar:
498 t = tarfile.TarInfo("foo")
499 t.size = 1024
500 tar.addfile(t, io.BytesIO(b"a" * 1024))
501
502 with open(tmpname, "r+b") as fobj:
503 fobj.truncate(size)
504
505 with tarfile.open(tmpname) as tar:
506 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
507 for t in tar:
508 pass
509
510 with tarfile.open(tmpname) as tar:
511 t = tar.next()
512
513 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
514 tar.extract(t, TEMPDIR, filter='data')
515
516 with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
517 tar.extractfile(t).read()
518
519 def test_length_zero_header(self):
520 # bpo-39017 (CVE-2019-20907): reading a zero-length header should fail

Callers

nothing calls this directly

Calls 9

addfileMethod · 0.80
assertRaisesRegexMethod · 0.80
extractfileMethod · 0.80
openFunction · 0.50
openMethod · 0.45
truncateMethod · 0.45
nextMethod · 0.45
extractMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected