Skip to content

Commit

Permalink
ext/phar: offsetExists should return false when file entry is not bas…
Browse files Browse the repository at this point in the history
…ed on PharFileInfo
  • Loading branch information
Girgias committed Jun 10, 2024
1 parent 6e92fdb commit 46be651
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3528,6 +3528,10 @@ PHP_METHOD(Phar, offsetExists)
}
RETURN_TRUE;
} else {
/* If the info class is not based on PharFileInfo, directories are not directly instantiable */
if (UNEXPECTED(!instanceof_function(phar_obj->spl.info_class, phar_ce_entry))) {
RETURN_FALSE;
}
if (zend_hash_str_exists(&phar_obj->archive->virtual_dirs, fname, (uint32_t) fname_len)) {
RETURN_TRUE;
}
Expand Down
6 changes: 3 additions & 3 deletions ext/phar/tests/phar_oo_011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ __halt_compiler();
bool(true)
object(PharFileInfo)#%d (2) {
["pathName":"SplFileInfo":private]=>
string(%s) "phar:///%s/phar_oo_011.phar.php/hi"
string(%d) "phar://%s/phar_oo_011.phar.php/hi"
["fileName":"SplFileInfo":private]=>
string(2) "hi"
}
bool(true)
phar:///%s/phar_oo_011.phar.php/hi/f.php
bool(true)
phar://%s/phar_oo_011.phar.php/hi/f.php
bool(false)
LogicException: Cannot use SplFileObject with directories
bool(true)
hi

0 comments on commit 46be651

Please sign in to comment.