Skip to content

Commit a9ecb72

Browse files
committed
Don't descend into symlinks when building context tar
Signed-off-by: Joffrey F <[email protected]>
1 parent af67415 commit a9ecb72

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docker/utils/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def match(p):
9393
# Whether this file is implicitely included / excluded.
9494
matched = default if hit is None else hit
9595
sub = list(filter(lambda p: p[1], sub))
96-
if os.path.isdir(cur):
96+
if os.path.isdir(cur) and not os.path.islink(cur):
9797
# Entirely skip directories if there are no chance any subfile will
9898
# be included.
9999
if all(not p[0] for p in sub) and not matched:

tests/unit/utils_test.py

+15
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,21 @@ def tar_test_negative_mtime_bug(self):
10581058
assert tar_data.getnames() == ['th.txt']
10591059
assert tar_data.getmember('th.txt').mtime == -3600
10601060

1061+
@pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='No symlinks on Windows')
1062+
def test_tar_directory_link(self):
1063+
dirs = ['a', 'b', 'a/c']
1064+
files = ['a/hello.py', 'b/utils.py', 'a/c/descend.py']
1065+
base = make_tree(dirs, files)
1066+
self.addCleanup(shutil.rmtree, base)
1067+
os.symlink(os.path.join(base, 'b'), os.path.join(base, 'a/c/b'))
1068+
with tar(base) as archive:
1069+
tar_data = tarfile.open(fileobj=archive)
1070+
names = tar_data.getnames()
1071+
for member in dirs + files:
1072+
assert member in names
1073+
assert 'a/c/b' in names
1074+
assert 'a/c/b/utils.py' not in names
1075+
10611076

10621077
class FormatEnvironmentTest(unittest.TestCase):
10631078
def test_format_env_binary_unicode_value(self):

0 commit comments

Comments
 (0)