@@ -70,10 +70,13 @@ def test_match_multiple_time(tmpdir):
7070 _test_library_includes (tmpdir , ['posix' , 'gnu' , 'bsd' , 'zlib' ], '#include <zlib.h>' , libinc )
7171 _test_library_includes (tmpdir , ['posix' , 'gnu' , 'bsd' , 'zlib' ], '#include <zlib.h>' , libinc )
7272
73- def _add_tar_member (tf , name , linkname = None , linktype = tarfile .SYMTYPE ):
73+ def _add_tar_member (tf , name , linkname = None , linktype = tarfile .SYMTYPE , dirmode = None ):
7474 info = tarfile .TarInfo (name )
7575 data = b''
76- if linkname is not None :
76+ if dirmode is not None :
77+ info .type = tarfile .DIRTYPE
78+ info .mode = dirmode
79+ elif linkname is not None :
7780 info .type = linktype
7881 info .linkname = linkname
7982 else :
@@ -167,3 +170,28 @@ def test_unpack_package_hardlink_missing_target(tmpdir):
167170 assert source_found
168171 assert os .path .isfile (os .path .join (temp_path , 'pkg' , 'main.c' ))
169172 assert not os .path .lexists (os .path .join (temp_path , 'pkg' , 'copy.c' ))
173+
174+ def test_unpack_package_link_in_readonly_dir (tmpdir ):
175+ work_path = str (tmpdir )
176+ outside_path = os .path .join (work_path , 'outside' )
177+ os .mkdir (outside_path )
178+ with open (os .path .join (outside_path , 'secret.c' ), 'w' , encoding = 'utf-8' ) as f :
179+ f .write ('int secret;\n ' )
180+ tgz = os .path .join (work_path , 'temp.tgz' )
181+ with tarfile .open (tgz , 'w:gz' ) as tf :
182+ _add_tar_member (tf , 'pkg/main.c' )
183+ # redirected out of temp by the next member, like in test_unpack_package_link_redirected_later
184+ _add_tar_member (tf , 'pkg/x.h/l.h' , linkname = 'd.h/../../../outside' )
185+ _add_tar_member (tf , 'pkg/x.h/d.h' , linkname = '.' )
186+ # a directory member with a header-like name makes the folder read-only after the links exist
187+ _add_tar_member (tf , 'pkg/x.h' , dirmode = 0o555 )
188+
189+ temp_path , source_found = unpack_package (work_path , tgz )
190+ assert source_found
191+ assert os .path .isfile (os .path .join (temp_path , 'pkg' , 'main.c' ))
192+ real_temp_path = os .path .realpath (temp_path )
193+ for name in ('l.h' , 'd.h' ):
194+ path = os .path .join (temp_path , 'pkg' , 'x.h' , name )
195+ if os .path .lexists (path ):
196+ assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
197+ assert os .listdir (outside_path ) == ['secret.c' ]
0 commit comments