Skip to content

Commit 01c6b48

Browse files
authored
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
1 parent 6a07400 commit 01c6b48

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ $pharconfig = 0;
1313
require_once 'files/phar_oo_test.inc';
1414

1515
$phar = new Phar($fname);
16-
$phar->setInfoClass('SplFileObject');
1716

1817
$phar['hi/f.php'] = 'hi';
1918
var_dump(isset($phar['hi']));
19+
var_dump($phar['hi']);
20+
var_dump(isset($phar['hi/f.php']));
21+
echo $phar['hi/f.php'];
22+
echo "\n";
23+
24+
$phar->setInfoClass('SplFileObject');
25+
$phar['hi/f.php'] = 'hi';
26+
var_dump(isset($phar['hi']));
27+
try {
28+
var_dump($phar['hi']);
29+
} catch (Throwable $e) {
30+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
31+
}
2032
var_dump(isset($phar['hi/f.php']));
2133
echo $phar['hi/f.php'];
2234
echo "\n";
@@ -27,7 +39,17 @@ echo "\n";
2739
unlink(__DIR__ . '/files/phar_oo_011.phar.php');
2840
__halt_compiler();
2941
?>
30-
--EXPECT--
42+
--EXPECTF--
43+
bool(true)
44+
object(PharFileInfo)#%d (2) {
45+
["pathName":"SplFileInfo":private]=>
46+
string(%d) "phar://%s/phar_oo_011.phar.php/hi"
47+
["fileName":"SplFileInfo":private]=>
48+
string(2) "hi"
49+
}
3150
bool(true)
51+
phar://%s/phar_oo_011.phar.php/hi/f.php
52+
bool(false)
53+
LogicException: Cannot use SplFileObject with directories
3254
bool(true)
3355
hi

0 commit comments

Comments
 (0)