#36741 [NEW]: userstreams testcase have off-by-one error on fseek()

From: Date: Wed, 15 Mar 2006 04:58:15 +0000
Subject: #36741 [NEW]: userstreams testcase have off-by-one error on fseek()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94356@lists.php.net to get a copy of this message
From: elliot dot li at gmail dot com Operating system: Linux PHP version: 5.1.2 PHP Bug Type: Streams related Bug description: userstreams testcase have off-by-one error on fseek() Description: ------------ This case(php-5.1.2/ext/standard/tests/file/userstreams.phpt) generates a bunch of random numbers and use them as offsets for fseek() test on a userstream. However, the range of these random numbers is [0, $DATALEN](rand(0, $DATALEN)), which should be [0, $DATALEN). ======== CODE SNIP FOLLOWS ======== /* generate some random seek offsets */ $position = 0; for ($i = 0; $i < 256; $i++) { $whence = $whence_map[array_rand($whence_map, 1)]; switch($whence) { case SEEK_SET: $offset = rand(0, $DATALEN); $position = $offset; break; case SEEK_END: $offset = -rand(0, $DATALEN); $position = $DATALEN + $offset; break; case SEEK_CUR: $offset = rand(0, $DATALEN); $offset -= $position; $position += $offset; break; } $seeks[] = array($whence, $offset, $position); } ======== CODE SNIP ABOVE ======== Reproduce code: --------------- Run this case on and on for a while, you can encounter this problem. I found this problem during a regression test, and reproduced it on my PC(Pentium 4 2.6GHz) within one day. Expected result: ---------------- No error should be reported if everything goes OK. Actual result: -------------- ========= LOG SNIP FOLLOWS ========= --[34] whence=SEEK_SET offset=32550 line_length=1024 position_should_be=32550 -- REAL: pos=(29175,32550,32550) ret=0 line[0]=`' USER: pos=(29175,29175,29175) ret=0 line[16]=`zl urnq vf ubzr ' ###################################### FAIL! ========= LOG SNIP ABOVE ========= 32550 is the total length of the userstream, so fseek($fp, 32550, SEEK_SET) must fail. I noticed another problem: mystream.stream_seek() would return a false on this condition, but the return value of fseek() is still 0! This would lead to the result that the failure of seeking in a userstream couldn't be noticed by the main program. -- Edit bug report at http://bugs.php.net/?id=36741&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36741&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36741&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36741&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36741&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36741&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36741&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36741&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36741&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36741&r=support Expected behavior: http://bugs.php.net/fix.php?id=36741&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36741&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36741&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36741&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36741&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36741&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36741&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36741&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36741&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36741&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36741&r=mysqlcfg

« previous php.bugs (#94356) next »