Skip to content

Commit cbb024c

Browse files
authored
Select rand_rangeXX() variant only based on the requested range (#9418)
This fixes an incompatibility when wrapping native 32-bit engines with a userland engine. The latter always used the 64-bit range function which then used two 32-bit numbers from the underlying engine to fill the 64-bit range, whereas the native implementation used only one. Now the selection of the range variant only depends on the requested range. A 32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a larger range uses the 64-bit variant. This was found in #9410 (comment)
1 parent de90edc commit cbb024c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP NEWS
1717
- Random:
1818
. Fixed bug GH-9415 (Randomizer::getInt(0, 2**32 - 1) with Mt19937
1919
always returns 1). (timwolla)
20+
. Fixed Randomizer::getInt() consistency for 32-bit engines. (timwolla)
2021

2122
- Streams:
2223
. Fixed bug GH-9316 ($http_response_header is wrong for long status line).

ext/random/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ PHPAPI zend_long php_random_range(const php_random_algo *algo, php_random_status
313313
{
314314
zend_ulong umax = (zend_ulong) max - (zend_ulong) min;
315315

316-
if (algo->generate_size == 0 || algo->generate_size > sizeof(uint32_t) || umax > UINT32_MAX) {
316+
if (umax > UINT32_MAX) {
317317
return (zend_long) (rand_range64(algo, status, umax) + min);
318318
}
319319

0 commit comments

Comments
 (0)