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

Side by Side Diff: Lib/tarfile.py

Issue 23228: Crashes when tarfile contains a symlink and unpack directory contain it too
Patch Set: Created 3 years, 5 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') | no next file with comments »
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 import struct 48 import struct
49 import copy 49 import copy
50 import re 50 import re
51 51
52 try: 52 try:
53 import grp, pwd 53 import grp, pwd
54 except ImportError: 54 except ImportError:
55 grp = pwd = None 55 grp = pwd = None
56 56
57 # os.symlink on Windows prior to 6.0 raises NotImplementedError 57 # os.symlink on Windows prior to 6.0 raises NotImplementedError
58 symlink_exception = (AttributeError, NotImplementedError) 58 symlink_exception = (AttributeError, NotImplementedError, OSError)
59 try:
60 # OSError (winerror=1314) will be raised if the caller does not hold the
61 # SeCreateSymbolicLinkPrivilege privilege
62 symlink_exception += (OSError,)
63 except NameError:
64 pass
65 59
66 # from tarfile import * 60 # from tarfile import *
67 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError", "ReadError", 61 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError", "ReadError",
68 "CompressionError", "StreamError", "ExtractError", "HeaderError", 62 "CompressionError", "StreamError", "ExtractError", "HeaderError",
69 "ENCODING", "USTAR_FORMAT", "GNU_FORMAT", "PAX_FORMAT", 63 "ENCODING", "USTAR_FORMAT", "GNU_FORMAT", "PAX_FORMAT",
70 "DEFAULT_FORMAT", "open"] 64 "DEFAULT_FORMAT", "open"]
71 65
72 #--------------------------------------------------------- 66 #---------------------------------------------------------
73 # tar constants 67 # tar constants
74 #--------------------------------------------------------- 68 #---------------------------------------------------------
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 # For systems that support symbolic and hard links. 2192 # For systems that support symbolic and hard links.
2199 if tarinfo.issym(): 2193 if tarinfo.issym():
2200 os.symlink(tarinfo.linkname, targetpath) 2194 os.symlink(tarinfo.linkname, targetpath)
2201 else: 2195 else:
2202 # See extract(). 2196 # See extract().
2203 if os.path.exists(tarinfo._link_target): 2197 if os.path.exists(tarinfo._link_target):
2204 os.link(tarinfo._link_target, targetpath) 2198 os.link(tarinfo._link_target, targetpath)
2205 else: 2199 else:
2206 self._extract_member(self._find_link_target(tarinfo), 2200 self._extract_member(self._find_link_target(tarinfo),
2207 targetpath) 2201 targetpath)
2208 except symlink_exception: 2202 except symlink_exception as e:
2203 # On Windows, OSError (winerror=1314) will be raised if the caller
2204 # does not hold the SeCreateSymbolicLinkPrivilege privilege.
2205 if getattr(e, "winerror", None) is None:
Martin Panter 2018/12/15 23:44:46 What about AttributeError and NotImplementedError,
2206 raise
2207
2209 try: 2208 try:
2210 self._extract_member(self._find_link_target(tarinfo), 2209 self._extract_member(self._find_link_target(tarinfo),
2211 targetpath) 2210 targetpath)
2212 except KeyError: 2211 except KeyError:
2213 raise ExtractError("unable to resolve link inside archive") 2212 raise ExtractError("unable to resolve link inside archive")
2214 2213
2215 def chown(self, tarinfo, targetpath, numeric_owner): 2214 def chown(self, tarinfo, targetpath, numeric_owner):
2216 """Set owner of targetpath according to tarinfo. If numeric_owner 2215 """Set owner of targetpath according to tarinfo. If numeric_owner
2217 is True, use .gid/.uid instead of .gname/.uname. 2216 is True, use .gid/.uid instead of .gname/.uname.
2218 """ 2217 """
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 tf.add(file_name) 2525 tf.add(file_name)
2527 2526
2528 if args.verbose: 2527 if args.verbose:
2529 print('{!r} file created.'.format(tar_name)) 2528 print('{!r} file created.'.format(tar_name))
2530 2529
2531 else: 2530 else:
2532 parser.exit(1, parser.format_help()) 2531 parser.exit(1, parser.format_help())
2533 2532
2534 if __name__ == '__main__': 2533 if __name__ == '__main__':
2535 main() 2534 main()
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_tarfile.py » ('j') | no next file with comments »

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