Skip to content

Commit

Permalink
random/standard: Adjust #13138 for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla committed Jan 14, 2024
1 parent f2f070a commit 00ea756
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 14 additions & 0 deletions ext/random/tests/03_randomizer/engine_unsafe_nul.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ try {
echo $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->getBytesFromString('123', 10));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
var_dump(randomizer()->getBytesFromString(str_repeat('a', 500), 10));
} catch (Random\BrokenRandomEngineError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
int(0)
Expand Down Expand Up @@ -320,3 +332,5 @@ array(1) {
}
Failed to generate an acceptable random number in 50 attempts
string(6) "oobarf"
string(10) "1111111111"
string(10) "aaaaaaaaaa"
5 changes: 2 additions & 3 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -6179,10 +6179,9 @@ PHPAPI bool php_array_pick_keys(const php_random_algo *algo, php_random_status *
goto fail;
}
if (zend_bitset_in(bitset, randval)) {
/* Use PHP_RANDOM_RANGE_ATTEMPTS instead of the hardcoded 50 for 8.3+. */
if (++failures > 50) {
if (++failures > PHP_RANDOM_RANGE_ATTEMPTS) {
if (!silent) {
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "Failed to generate an acceptable random number in %d attempts", 50);
zend_throw_error(random_ce_Random_BrokenRandomEngineError, "Failed to generate an acceptable random number in %d attempts", PHP_RANDOM_RANGE_ATTEMPTS);
}

goto fail;
Expand Down

0 comments on commit 00ea756

Please sign in to comment.