Skip to content

Commit

Permalink
Bail on exception during delayed autoload
Browse files Browse the repository at this point in the history
We shouldn't try to load further classes if one autoload throws.

This fixes oss-fuzz #38881, though I believe there are still two
deeper issues here: 1) Why do we allow autoloading with an active
exception? 2) Exception save & restore should probably also save
and restore the exception opline.
  • Loading branch information
nikic committed Sep 23, 2021
1 parent 4304542 commit be82173
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Zend/tests/exception_during_variance_autoload.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Exception during delayed variance autoload
--FILE--
<?php
spl_autoload_register(function($class) {
echo "$class\n";
if ($class == 'X') {
new Y;
}
if ($class == 'Y') {
new Q;
}
});
class A {
function method(): X {}
}
class B extends A {
function method(): Y {}
}
?>
--EXPECTF--
Y
Q

Warning: Uncaught Error: Class "Q" not found in %s:%d
Stack trace:
#0 %s(%d): {closure}('Y')
#1 {main}
thrown in %s on line %d

Fatal error: Could not check compatibility between B::method(): Y and A::method(): X, because class Y is not available in %s on line %d
3 changes: 3 additions & 0 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,9 @@ static void load_delayed_classes() {

ZEND_HASH_FOREACH_STR_KEY(delayed_autoloads, name) {
zend_lookup_class(name);
if (EG(exception)) {
break;
}
} ZEND_HASH_FOREACH_END();

zend_hash_destroy(delayed_autoloads);
Expand Down

0 comments on commit be82173

Please sign in to comment.