@@ -254,3 +254,28 @@ def test_unpack_package_link_in_readonly_dir(tmpdir):
254254 if os .path .lexists (path ):
255255 assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
256256 assert os .listdir (outside_path ) == ['secret.c' ]
257+
258+ def test_unpack_package_link_in_unreadable_dir (tmpdir ):
259+ work_path = str (tmpdir )
260+ outside_path = os .path .join (work_path , 'outside' )
261+ os .mkdir (outside_path )
262+ with open (os .path .join (outside_path , 'secret.c' ), 'w' , encoding = 'utf-8' ) as f :
263+ f .write ('int secret;\n ' )
264+ tgz = os .path .join (work_path , 'temp.tgz' )
265+ with tarfile .open (tgz , 'w:gz' ) as tf :
266+ _add_tar_member (tf , 'pkg/main.c' )
267+ # redirected out of temp by the next member, like in test_unpack_package_link_redirected_later
268+ _add_tar_member (tf , 'pkg/q.h/l.h' , linkname = 'd.h/../../../outside' )
269+ _add_tar_member (tf , 'pkg/q.h/d.h' , linkname = '.' )
270+ # a directory member with a header-like name makes the folder unlistable after the links exist
271+ _add_tar_member (tf , 'pkg/q.h' , dirmode = 0o311 )
272+
273+ temp_path , source_found = unpack_package (work_path , tgz )
274+ assert source_found
275+ assert os .path .isfile (os .path .join (temp_path , 'pkg' , 'main.c' ))
276+ real_temp_path = os .path .realpath (temp_path )
277+ for name in ('l.h' , 'd.h' ):
278+ path = os .path .join (temp_path , 'pkg' , 'q.h' , name )
279+ if os .path .lexists (path ):
280+ assert os .path .commonpath ([real_temp_path , os .path .realpath (path )]) == real_temp_path
281+ assert os .listdir (outside_path ) == ['secret.c' ]
0 commit comments