Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
26 changes: 24 additions & 2 deletions ext/phar/tests/phar_oo_011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Loading