Skip to content

Fix GH-18018: RC1 data returned from offsetGet causes UAF in ArrayObject #18034

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,14 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object
}
}

/* empty() check the value is not falsy, isset() only check it is not null */
bool result = check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL;

if (value == &rv) {
zval_ptr_dtor(&rv);
}

/* empty() check the value is not falsy, isset() only check it is not null */
return check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL;
return result;
} /* }}} */

static int spl_array_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */
Expand Down
20 changes: 20 additions & 0 deletions ext/spl/tests/gh18018.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-18018 (RC1 data returned from offsetGet causes UAF in ArrayObject)
--FILE--
<?php
class Crap extends ArrayObject
{
public function offsetGet($offset): mixed
{
return [random_int(1,1)];
}
}

$values = ['qux' => 1];

$object = new Crap($values);

var_dump(empty($object['qux']));
?>
--EXPECT--
bool(false)
Loading