@@ -195,3 +195,28 @@ def test_unpack_package_link_in_readonly_dir(tmpdir):
195195 if os .path .lexists (path ):
196196 assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
197197 assert os .listdir (outside_path ) == ['secret.c' ]
198+
199+ def test_unpack_package_link_in_unreadable_dir (tmpdir ):
200+ work_path = str (tmpdir )
201+ outside_path = os .path .join (work_path , 'outside' )
202+ os .mkdir (outside_path )
203+ with open (os .path .join (outside_path , 'secret.c' ), 'w' , encoding = 'utf-8' ) as f :
204+ f .write ('int secret;\n ' )
205+ tgz = os .path .join (work_path , 'temp.tgz' )
206+ with tarfile .open (tgz , 'w:gz' ) as tf :
207+ _add_tar_member (tf , 'pkg/main.c' )
208+ # redirected out of temp by the next member, like in test_unpack_package_link_redirected_later
209+ _add_tar_member (tf , 'pkg/q.h/l.h' , linkname = 'd.h/../../../outside' )
210+ _add_tar_member (tf , 'pkg/q.h/d.h' , linkname = '.' )
211+ # a directory member with a header-like name makes the folder unlistable after the links exist
212+ _add_tar_member (tf , 'pkg/q.h' , dirmode = 0o311 )
213+
214+ temp_path , source_found = unpack_package (work_path , tgz )
215+ assert source_found
216+ assert os .path .isfile (os .path .join (temp_path , 'pkg' , 'main.c' ))
217+ real_temp_path = os .path .realpath (temp_path )
218+ for name in ('l.h' , 'd.h' ):
219+ path = os .path .join (temp_path , 'pkg' , 'q.h' , name )
220+ if os .path .lexists (path ):
221+ assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
222+ assert os .listdir (outside_path ) == ['secret.c' ]
0 commit comments