Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27992)

Side by Side Diff: Lib/test/test_tarfile.py

Issue 23228: Crashes when tarfile contains a symlink and unpack directory contain it too
Patch Set: Created 3 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« Lib/tarfile.py ('K') | « Lib/tarfile.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import sys 1 import sys
2 import os 2 import os
3 import io 3 import io
4 from hashlib import md5 4 from hashlib import md5
5 from contextlib import contextmanager 5 from contextlib import contextmanager
6 6
7 import unittest 7 import unittest
8 import unittest.mock 8 import unittest.mock
9 import tarfile 9 import tarfile
10 10
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 # Test hardlink extraction (e.g. bug #857297). 517 # Test hardlink extraction (e.g. bug #857297).
518 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: 518 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
519 tar.extract("ustar/regtype", TEMPDIR) 519 tar.extract("ustar/regtype", TEMPDIR)
520 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/regtype ")) 520 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/regtype "))
521 521
522 tar.extract("ustar/lnktype", TEMPDIR) 522 tar.extract("ustar/lnktype", TEMPDIR)
523 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/lnktype ")) 523 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/lnktype "))
524 with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: 524 with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f:
525 data = f.read() 525 data = f.read()
526 self.assertEqual(md5sum(data), md5_regtype) 526 self.assertEqual(md5sum(data), md5_regtype)
527
528 @support.skip_unless_symlink
529 def test_extract_symlink(self):
530 # Test symlink extraction (e.g. bug #23228).
531 with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
532 tar.extract("ustar/regtype", TEMPDIR)
533 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/regtype "))
527 534
528 tar.extract("ustar/symtype", TEMPDIR) 535 tar.extract("ustar/symtype", TEMPDIR)
529 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/symtype ")) 536 self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/symtype "))
530 with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: 537 with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f:
531 data = f.read() 538 data = f.read()
532 self.assertEqual(md5sum(data), md5_regtype) 539 self.assertEqual(md5sum(data), md5_regtype)
533 540
541 self.assertRaises(FileExistsError, tar.extract, "ustar/symtype", TEM PDIR)
542
534 def test_extractall(self): 543 def test_extractall(self):
535 # Test if extractall() correctly restores directory permissions 544 # Test if extractall() correctly restores directory permissions
536 # and times (see issue1735). 545 # and times (see issue1735).
537 tar = tarfile.open(tarname, encoding="iso8859-1") 546 tar = tarfile.open(tarname, encoding="iso8859-1")
538 DIR = os.path.join(TEMPDIR, "extractall") 547 DIR = os.path.join(TEMPDIR, "extractall")
539 os.mkdir(DIR) 548 os.mkdir(DIR)
540 try: 549 try:
541 directories = [t for t in tar if t.isdir()] 550 directories = [t for t in tar if t.isdir()]
542 tar.extractall(DIR, directories) 551 tar.extractall(DIR, directories)
543 for tarinfo in directories: 552 for tarinfo in directories:
(...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 testtarnames.append(c.tarname) 2553 testtarnames.append(c.tarname)
2545 with c.open(c.tarname, "wb") as tar: 2554 with c.open(c.tarname, "wb") as tar:
2546 tar.write(data) 2555 tar.write(data)
2547 2556
2548 def tearDownModule(): 2557 def tearDownModule():
2549 if os.path.exists(TEMPDIR): 2558 if os.path.exists(TEMPDIR):
2550 support.rmtree(TEMPDIR) 2559 support.rmtree(TEMPDIR)
2551 2560
2552 if __name__ == "__main__": 2561 if __name__ == "__main__":
2553 unittest.main() 2562 unittest.main()
OLDNEW
« Lib/tarfile.py ('K') | « Lib/tarfile.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+