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

Side by Side Diff: Lib/tarfile.py

Issue 23228: Crashes when tarfile contains a symlink and unpack directory contain it too
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | Lib/test/test_tarfile.py » ('j') | Lib/test/test_tarfile.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 #------------------------------------------------------------------- 2 #-------------------------------------------------------------------
3 # tarfile.py 3 # tarfile.py
4 #------------------------------------------------------------------- 4 #-------------------------------------------------------------------
5 # Copyright (C) 2002 Lars Gustaebel <lars@gustaebel.de> 5 # Copyright (C) 2002 Lars Gustaebel <lars@gustaebel.de>
6 # All rights reserved. 6 # All rights reserved.
7 # 7 #
8 # Permission is hereby granted, free of charge, to any person 8 # Permission is hereby granted, free of charge, to any person
9 # obtaining a copy of this software and associated documentation 9 # obtaining a copy of this software and associated documentation
10 # files (the "Software"), to deal in the Software without 10 # files (the "Software"), to deal in the Software without
(...skipping 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 os.makedev(tarinfo.devmajor, tarinfo.devminor)) 2170 os.makedev(tarinfo.devmajor, tarinfo.devminor))
2171 2171
2172 def makelink(self, tarinfo, targetpath): 2172 def makelink(self, tarinfo, targetpath):
2173 """Make a (symbolic) link called targetpath. If it cannot be created 2173 """Make a (symbolic) link called targetpath. If it cannot be created
2174 (platform limitation), we try to make a copy of the referenced file 2174 (platform limitation), we try to make a copy of the referenced file
2175 instead of a link. 2175 instead of a link.
2176 """ 2176 """
2177 try: 2177 try:
2178 # For systems that support symbolic and hard links. 2178 # For systems that support symbolic and hard links.
2179 if tarinfo.issym(): 2179 if tarinfo.issym():
2180 # a symlink with that name exists already, we need to replace
2181 # it with our version (see #23228)
2182 if os.path.lexists(targetpath):
2183 os.remove(targetpath)
barry 2015/01/13 17:38:20 I'm a little concerned about the security implicat
2180 os.symlink(tarinfo.linkname, targetpath) 2184 os.symlink(tarinfo.linkname, targetpath)
2181 else: 2185 else:
2182 # See extract(). 2186 # See extract().
2183 if os.path.exists(tarinfo._link_target): 2187 if os.path.exists(tarinfo._link_target):
2184 os.link(tarinfo._link_target, targetpath) 2188 os.link(tarinfo._link_target, targetpath)
2185 else: 2189 else:
2186 self._extract_member(self._find_link_target(tarinfo), 2190 self._extract_member(self._find_link_target(tarinfo),
2187 targetpath) 2191 targetpath)
2188 except symlink_exception: 2192 except symlink_exception:
2189 try: 2193 try:
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 tf.add(file_name) 2517 tf.add(file_name)
2514 2518
2515 if args.verbose: 2519 if args.verbose:
2516 print('{!r} file created.'.format(tar_name)) 2520 print('{!r} file created.'.format(tar_name))
2517 2521
2518 else: 2522 else:
2519 parser.exit(1, parser.format_help()) 2523 parser.exit(1, parser.format_help())
2520 2524
2521 if __name__ == '__main__': 2525 if __name__ == '__main__':
2522 main() 2526 main()
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_tarfile.py » ('j') | Lib/test/test_tarfile.py » ('J')

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