@@ -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' ]
0 commit comments