Skip to content

Commit

Permalink
Fix GH-17516: SplFileTempObject::getPathInfo() crash on invalid class.
Browse files Browse the repository at this point in the history
This no longer caught the case where an non SplFileInfo/inherited class
of nwas passed since the refactoring in 8.4.
  • Loading branch information
devnexen committed Jan 19, 2025
1 parent 05a1c04 commit 82ea3f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,9 @@ PHP_METHOD(SplFileInfo, getPathInfo)

if (ce == NULL) {
ce = intern->info_class;
} else if (!instanceof_function(ce, spl_ce_SplFileInfo)) {
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));
RETURN_THROWS();
}

path = spl_filesystem_object_get_pathname(intern);
Expand Down
24 changes: 24 additions & 0 deletions ext/spl/tests/gh17516.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-17516 SplTempFileObject::getPathInfo() crashes on invalid class ID.
--FILE--
<?php
$cls = new SplTempFileObject();
class SplFileInfoChild extends SplFileInfo {}
class BadSplFileInfo {}

var_dump($cls->getPathInfo('SplFileInfoChild'));

try {
$cls->getPathInfo('BadSplFileInfo');
} catch (\TypeError $e) {
echo $e->getMessage();
}
?>
--EXPECT--
object(SplFileInfoChild)#2 (2) {
["pathName":"SplFileInfo":private]=>
string(4) "php:"
["fileName":"SplFileInfo":private]=>
string(4) "php:"
}
SplFileInfo::getPathInfo(): Argument #1 ($class) must be a class name derived from SplFileInfo or null, BadSplFileInfo given

0 comments on commit 82ea3f5

Please sign in to comment.