(self)
| 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 |
nothing calls this directly
no test coverage detected