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

From: Date: Wed, 18 Jun 2008 16:20:47 +0000
Subject: #45301 [Opn]: 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-125850@lists.php.net to get a copy of this message
 ID:               45301
 Updated by:       pajoye@php.net
 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:

On a related note: #45184


Previous Comments:
------------------------------------------------------------------------

[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



Thread (16 messages)

« previous php.bugs (#125850) next »