File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -432,6 +432,8 @@ PHP_METHOD(Random_Randomizer, getBytesFromString)
432
432
mask |= mask >> 2 ;
433
433
mask |= mask >> 4 ;
434
434
435
+ /* Example: if mask is 0xAB, will be 0xABABABABABABABAB */
436
+ uint64_t mask_repeat = (~((uint64_t ) 0 ) / 0xff ) * mask ;
435
437
int failures = 0 ;
436
438
while (total_size < length ) {
437
439
php_random_result result = engine .algo -> generate (engine .state );
@@ -440,8 +442,9 @@ PHP_METHOD(Random_Randomizer, getBytesFromString)
440
442
RETURN_THROWS ();
441
443
}
442
444
445
+ uint64_t offsets = result .result & mask_repeat ;
443
446
for (size_t i = 0 ; i < result .size ; i ++ ) {
444
- uint64_t offset = ( result . result >> (i * 8 )) & mask ;
447
+ uint64_t offset = offsets >> (i * 8 ) & 0xff ;
445
448
446
449
if (offset > max_offset ) {
447
450
if (++ failures > PHP_RANDOM_RANGE_ATTEMPTS ) {
You can’t perform that action at this time.
0 commit comments