Phar offset exist issue with entry classes not based on PharFileInfo (#14503)

* ext/phar: expand test to cover issue with offsetGet

* ext/phar: offsetExists should return false when file entry is not based on PharFileInfo
This commit is contained in:
Gina Peter Banyard 2024-08-23 21:06:28 +01:00 committed by GitHub
parent 6a07400699
commit 01c6b48e31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -3529,6 +3529,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;
}
RETURN_BOOL(zend_hash_exists(&phar_obj->archive->virtual_dirs, file_name));
}
}

View file

@ -13,10 +13,22 @@ $pharconfig = 0;
require_once 'files/phar_oo_test.inc';
$phar = new Phar($fname);
$phar->setInfoClass('SplFileObject');
$phar['hi/f.php'] = 'hi';
var_dump(isset($phar['hi']));
var_dump($phar['hi']);
var_dump(isset($phar['hi/f.php']));
echo $phar['hi/f.php'];
echo "\n";
$phar->setInfoClass('SplFileObject');
$phar['hi/f.php'] = 'hi';
var_dump(isset($phar['hi']));
try {
var_dump($phar['hi']);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
var_dump(isset($phar['hi/f.php']));
echo $phar['hi/f.php'];
echo "\n";
@ -27,7 +39,17 @@ echo "\n";
unlink(__DIR__ . '/files/phar_oo_011.phar.php');
__halt_compiler();
?>
--EXPECT--
--EXPECTF--
bool(true)
object(PharFileInfo)#%d (2) {
["pathName":"SplFileInfo":private]=>
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(false)
LogicException: Cannot use SplFileObject with directories
bool(true)
hi