Skip to content

Commit 6d6d7d6

Browse files
committed
donate-cpu: extract the checked tar member instead of looking it up by name
1 parent 2751bea commit 6d6d7d6

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎test/tools/donate_cpu_lib_test.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ def test_scan_package_assertion_failure_no_gdb_stacktrace(tmpdir, monkeypatch):
129129
'src/a.c:0:0: error: Internal error: Child process crashed with signal 6 [cppcheckError]\n' \
130130
'src/b.c:0:0: error: Internal error: Child process crashed with signal 6 [cppcheckError]\n'
131131

132-
def _add_tar_member(tf, name, linkname=None):
132+
def _add_tar_member(tf, name, linkname=None, linktype=tarfile.SYMTYPE):
133133
info = tarfile.TarInfo(name)
134134
data = b''
135135
if linkname is not None:
136-
info.type = tarfile.SYMTYPE
136+
info.type = linktype
137137
info.linkname = linkname
138138
else:
139139
data = b'int x;\n'
@@ -155,3 +155,27 @@ def test_unpack_package_outside_temp(tmpdir):
155155
assert source_found
156156
assert os.path.isfile(os.path.join(temp_path, 'pkg', 'main.c'))
157157
assert os.listdir(outside_path) == []
158+
159+
def test_unpack_package_duplicate_name(tmpdir):
160+
work_path = str(tmpdir)
161+
outside_path = os.path.join(work_path, 'outside')
162+
os.mkdir(outside_path)
163+
outside_file = os.path.join(outside_path, 'target.c')
164+
with open(outside_file, 'w', encoding='utf-8') as f:
165+
f.write('int y;\n')
166+
tgz = os.path.join(work_path, 'temp.tgz')
167+
with tarfile.open(tgz, 'w:gz') as tf:
168+
# a harmless member followed by a link with the same name that points outside temp
169+
_add_tar_member(tf, 'pkg/sym.c')
170+
_add_tar_member(tf, 'pkg/sym.c', linkname=outside_file)
171+
_add_tar_member(tf, 'pkg/hard.c')
172+
_add_tar_member(tf, 'pkg/hard.c', linkname='../outside/target.c', linktype=tarfile.LNKTYPE)
173+
174+
temp_path, source_found = unpack_package(work_path, tgz)
175+
assert source_found
176+
for name in ('sym.c', 'hard.c'):
177+
path = os.path.join(temp_path, 'pkg', name)
178+
assert os.path.isfile(path)
179+
assert not os.path.islink(path)
180+
assert not os.path.samefile(path, outside_file)
181+
assert os.listdir(outside_path) == ['target.c']

‎tools/donate_cpu_lib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def unpack_package(work_path, tgz, cpp_only=False, c_only=False, skip_files=None
407407
skipped += 1
408408
continue
409409
try:
410-
tf.extract(member.name, temp_path, **extract_args)
410+
tf.extract(member, temp_path, **extract_args)
411411
if is_source:
412412
source_found = True
413413
extracted += 1

0 commit comments

Comments
 (0)