Skip to content

Fix OSS-Fuzz #427814456 #18951

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

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions Zend/tests/numeric_strings/oss_fuzz_427814456.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
OSS-Fuzz #427814456
--FILE--
<?php
set_error_handler(function(){unset($GLOBALS['x']);});
$x = str_repeat("3e33", random_int(2, 2));
$x & true;
echo "Done\n";
?>
--EXPECT--
Done
7 changes: 6 additions & 1 deletion Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval *
zend_long lval;
double dval;
bool trailing_data = false;
zend_string *op_ref = NULL; /* protect against error handlers */

/* For BC reasons we allow errors so that we can warn on leading numeric string */
type = is_numeric_string_ex(Z_STRVAL_P(op), Z_STRLEN_P(op), &lval, &dval,
Expand All @@ -410,6 +411,9 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval *
return 0;
}
if (UNEXPECTED(trailing_data)) {
if (type != IS_LONG) {
op_ref = zend_string_copy(Z_STR_P(op));
}
zend_error(E_WARNING, "A non-numeric value encountered");
if (UNEXPECTED(EG(exception))) {
*failed = 1;
Expand All @@ -425,11 +429,12 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval *
*/
lval = zend_dval_to_lval_cap(dval);
if (!zend_is_long_compatible(dval, lval)) {
zend_incompatible_string_to_long_error(Z_STR_P(op));
zend_incompatible_string_to_long_error(op_ref ? op_ref : Z_STR_P(op));
if (UNEXPECTED(EG(exception))) {
*failed = 1;
}
}
zend_tmp_string_release(op_ref);
return lval;
}
}
Expand Down
Loading