Skip to content

Commit 69451e4

Browse files
committed
ext/phar: offsetExists should return false when file entry is not based on PharFileInfo
1 parent 3a286c1 commit 69451e4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ext/phar/phar_object.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,6 +3529,10 @@ PHP_METHOD(Phar, offsetExists)
35293529
}
35303530
RETURN_TRUE;
35313531
} else {
3532+
/* If the info class is not based on PharFileInfo, directories are not directly instantiable */
3533+
if (UNEXPECTED(!instanceof_function(phar_obj->spl.info_class, phar_ce_entry))) {
3534+
RETURN_FALSE;
3535+
}
35323536
RETURN_BOOL(zend_hash_exists(&phar_obj->archive->virtual_dirs, file_name));
35333537
}
35343538
}

ext/phar/tests/phar_oo_011.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ __halt_compiler();
4343
bool(true)
4444
object(PharFileInfo)#%d (2) {
4545
["pathName":"SplFileInfo":private]=>
46-
string(%s) "phar:///%s/phar_oo_011.phar.php/hi"
46+
string(%d) "phar://%s/phar_oo_011.phar.php/hi"
4747
["fileName":"SplFileInfo":private]=>
4848
string(2) "hi"
4949
}
5050
bool(true)
51-
phar:///%s/phar_oo_011.phar.php/hi/f.php
52-
bool(true)
51+
phar://%s/phar_oo_011.phar.php/hi/f.php
52+
bool(false)
5353
LogicException: Cannot use SplFileObject with directories
5454
bool(true)
5555
hi

0 commit comments

Comments
 (0)