#45301 [Com]: Serious flaw in random related functions and possibly file or memory corruption

From: Date: Wed, 18 Jun 2008 18:06:09 +0000
Subject: #45301 [Com]: Serious flaw in random related functions and possibly file or memory corruption
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125854@lists.php.net to get a copy of this message
ID: 45301 Comment by: sv4php at fmethod dot com Reported By: payton2558 at googlemail dot com Status: Open Bug Type: Unknown/Other Function Operating System: Windows XP 32, Vista 32 PHP Version: 5.2.6 New Comment: Confirmed on Apache 2.2, Windows XP SP2 with PHP 5.2.6. Confirmed also without building files (just building the array directly in a loop). Requires Windows, doesn't seem to affect mt_rand(); Previous Comments: ------------------------------------------------------------------------ [2008-06-18 16:20:47] pajoye@php.net On a related note: #45184 ------------------------------------------------------------------------ [2008-06-18 16:05:00] payton2558 at googlemail dot com Description: ------------ The reproduce code demonstrates the bug. You can modify the code in different ways to affect the severity of the output. Appears to require Windows. Please note I have tested on 2 different machines and 3 versions of php. I have also confirmed this with a couple of users on IRC. mt_rand may also be affected but not as badly Unrelated: bugs.php your CAPTCHA system is the worst I could ever expect for a programming related group Reproduce code: --------------- <?php function RandomNumber() { $word1 = file('word1.txt'); // word1 and word2.txt can be made by fwriting "word\n" 50000 times. Different filesizes affect bug. $word2 = file('word2.txt'); $rword1 = trim($word1[array_rand($word1)]); $rword2 = trim($word2[array_rand($word2)]); $rnum = rand(1,999); return $rnum; } for ($i=0; $i<20; $i++) { echo RandomNumber()."\n"; } ?> Expected result: ---------------- 20 random looking numbers Actual result: -------------- 20 identical numbers or in other cases, severely unrandom numbers ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45301&edit=1

« previous php.bugs (#125854) next »