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

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 4 years, 10 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 5
6 import unittest 6 import unittest
7 import tarfile 7 import tarfile
8 import tempfile
8 9
9 from test import support, script_helper 10 from test import support, script_helper
10 11
11 # Check for our compression modules. 12 # Check for our compression modules.
12 try: 13 try:
13 import gzip 14 import gzip
14 except ImportError: 15 except ImportError:
15 gzip = None 16 gzip = None
16 try: 17 try:
17 import bz2 18 import bz2
(...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 tarfile.open(fileobj=MyBytesIO(data[:x]), mode=mode) 2160 tarfile.open(fileobj=MyBytesIO(data[:x]), mode=mode)
2160 except tarfile.ReadError: 2161 except tarfile.ReadError:
2161 pass # we have no interest in ReadErrors 2162 pass # we have no interest in ReadErrors
2162 2163
2163 def test_partial_input(self): 2164 def test_partial_input(self):
2164 self._test_partial_input("r") 2165 self._test_partial_input("r")
2165 2166
2166 def test_partial_input_bz2(self): 2167 def test_partial_input_bz2(self):
2167 self._test_partial_input("r:bz2") 2168 self._test_partial_input("r:bz2")
2168 2169
2170
2171 @unittest.skipIf(hasattr(os, "link"), "requires os.link to be missing")
2172 class TestTarfileLinkExtract(unittest.TestCase):
2173 """Regression test for #23228"""
2174
2175 def setUp(self):
2176 self.tempdir = tempfile.mkdtemp()
2177 self.cwd = os.getcwd()
barry 2015/01/13 17:38:20 I'd probably move the chdir into a try/finally ins
2178 os.chdir(self.tempdir)
2179
2180 def tearDown(self):
2181 os.chdir(self.cwd)
2182 support.rmtree(self.tempdir)
2183
2184 def test_tarfile_crash(self):
2185 os.mkdir("run")
2186 os.mkdir("var")
2187 os.symlink("run", "var/run")
2188 tarname = "lala.tar"
2189 with tarfile.open(tarname, "w") as w:
2190 w.add("run")
2191 w.add("var")
2192 with tarfile.open(tarname, "r") as r:
2193 r.extractall(".")
2194
2169 2195
2170 def setUpModule(): 2196 def setUpModule():
2171 support.unlink(TEMPDIR) 2197 support.unlink(TEMPDIR)
2172 os.makedirs(TEMPDIR) 2198 os.makedirs(TEMPDIR)
2173 2199
2174 global testtarnames 2200 global testtarnames
2175 testtarnames = [tarname] 2201 testtarnames = [tarname]
2176 with open(tarname, "rb") as fobj: 2202 with open(tarname, "rb") as fobj:
2177 data = fobj.read() 2203 data = fobj.read()
2178 2204
2179 # Create compressed tarfiles. 2205 # Create compressed tarfiles.
2180 for c in GzipTest, Bz2Test, LzmaTest: 2206 for c in GzipTest, Bz2Test, LzmaTest:
2181 if c.open: 2207 if c.open:
2182 support.unlink(c.tarname) 2208 support.unlink(c.tarname)
2183 testtarnames.append(c.tarname) 2209 testtarnames.append(c.tarname)
2184 with c.open(c.tarname, "wb") as tar: 2210 with c.open(c.tarname, "wb") as tar:
2185 tar.write(data) 2211 tar.write(data)
2186 2212
2187 def tearDownModule(): 2213 def tearDownModule():
2188 if os.path.exists(TEMPDIR): 2214 if os.path.exists(TEMPDIR):
2189 support.rmtree(TEMPDIR) 2215 support.rmtree(TEMPDIR)
2190 2216
2191 if __name__ == "__main__": 2217 if __name__ == "__main__":
2192 unittest.main() 2218 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+