Skip to content

Convert warnings to ValueError #4988

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

Merged
merged 1 commit into from
Dec 8, 2019
Merged
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
8 changes: 4 additions & 4 deletions ext/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ static PHP_FUNCTION(json_decode)
}

if (depth <= 0) {
php_error_docref(NULL, E_WARNING, "Depth must be greater than zero");
RETURN_NULL();
zend_value_error("Depth must be greater than zero");
return;
}

if (depth > INT_MAX) {
php_error_docref(NULL, E_WARNING, "Depth must be lower than %d", INT_MAX);
RETURN_NULL();
zend_value_error("Depth must be lower than %d", INT_MAX);
return;
}

/* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */
Expand Down
9 changes: 6 additions & 3 deletions ext/json/tests/bug72787.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ Bug #72787 (json_decode reads out of bounds)
--FILE--
<?php

var_dump(json_decode('[]', false, 0x100000000));
try {
var_dump(json_decode('[]', false, 0x100000000));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
Warning: json_decode(): Depth must be lower than %d in %s on line %d
NULL
Depth must be lower than %d
13 changes: 8 additions & 5 deletions ext/json/tests/json_decode_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ Test json_decode() function : error conditions
echo "*** Testing json_decode() : error conditions ***\n";

echo "\n-- Testing json_decode() function with depth below 0 --\n";
var_dump(json_decode('"abc"', true, -1));

try {
var_dump(json_decode('"abc"', true, -1));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
--EXPECT--
*** Testing json_decode() : error conditions ***

-- Testing json_decode() function with depth below 0 --

Warning: json_decode(): Depth must be greater than zero in %s on line %d
NULL
Depth must be greater than zero