Skip to content

Commit c82e31b

Browse files
committed
Fix phpGH-17516: SplFileTempObject::getPathInfo() crash on invalid class.
This no longer caught the case where an non SplFileInfo/inherited class of nwas passed since the refactoring in 8.4. close phpGH-17517
1 parent 7cc8719 commit c82e31b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ PHP NEWS
7878
- SPL:
7979
. Fixed bug GH-15833 (Segmentation fault (access null pointer) in
8080
ext/spl/spl_array.c). (nielsdos)
81+
. Fixed bug GH-17516 (SplFileTempObject::getPathInfo() Undefined behavior
82+
on invalid class). (David Carlier)
8183

8284
- Standard:
8385
. Fixed bug GH-17447 (Assertion failure when array popping a self addressing

ext/spl/spl_directory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,9 @@ PHP_METHOD(SplFileInfo, getPathInfo)
13681368

13691369
if (ce == NULL) {
13701370
ce = intern->info_class;
1371+
} else if (!instanceof_function(ce, spl_ce_SplFileInfo)) {
1372+
zend_argument_type_error(1, "must be a class name derived from %s or null, %s given", ZSTR_VAL(spl_ce_SplFileInfo->name), ZSTR_VAL(ce->name));
1373+
RETURN_THROWS();
13711374
}
13721375

13731376
path = spl_filesystem_object_get_pathname(intern);

ext/spl/tests/gh17516.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-17516 SplTempFileObject::getPathInfo() crashes on invalid class ID.
3+
--FILE--
4+
<?php
5+
$cls = new SplTempFileObject();
6+
class SplFileInfoChild extends SplFileInfo {}
7+
class BadSplFileInfo {}
8+
9+
var_dump($cls->getPathInfo('SplFileInfoChild'));
10+
11+
try {
12+
$cls->getPathInfo('BadSplFileInfo');
13+
} catch (\TypeError $e) {
14+
echo $e->getMessage();
15+
}
16+
?>
17+
--EXPECT--
18+
object(SplFileInfoChild)#2 (2) {
19+
["pathName":"SplFileInfo":private]=>
20+
string(4) "php:"
21+
["fileName":"SplFileInfo":private]=>
22+
string(4) "php:"
23+
}
24+
SplFileInfo::getPathInfo(): Argument #1 ($class) must be a class name derived from SplFileInfo or null, BadSplFileInfo given

0 commit comments

Comments
 (0)