#47171 [NEW]: Incorrect tell values when trying to seek beyond file range
| From: | d_kelsey at uk dot ibm dot com | Date: | Tue, 20 Jan 2009 17:24:01 +0000 |
| Subject: | #47171 [NEW]: Incorrect tell values when trying to seek beyond file range | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-133074@lists.php.net to get a copy of this message | ||
From: d_kelsey at uk dot ibm dot com
Operating system: Windows
PHP version: 5.2.8
PHP Bug Type: Zlib Related
Bug description: Incorrect tell values when trying to seek beyond file range
Description:
------------
When attempting to seek a zlib stream outside the range of the file eg -50
or 2000 (and the uncompressed length is < 2000) in either read or write
mode, after the seek operation a gztell call returns false. In most cases
the file pointer doesn't move so I can perform further reads or writes but
the tell value returns now an invalid value.
If a attempt to seek forward in read mode beyond the end of the
uncompressed stream it looks like the file pointer remains at the end of
the stream as a subsequent read returns nothing.
In all cases I would expect
- seek & gzseek to return -1
- the file pointer to remain where it was
- the tell to return the same value as before the seek
In other words the operation fails and nothing changes.
Reproduce code:
---------------
<?php
$f = dirname(__FILE__)."/004.txt.gz";
$h = gzopen($f, 'r');
echo "move to the 40th byte\n";
echo "seek=";
var_dump(gzseek( $h, 40 ) );
echo "tell=".gztell($h)."\n";
echo "try to move beyond the file\n";
echo "seek=";
var_dump(gzseek( $h, 1000 ) );
echo "tell=";
var_dump(gztell($h));
var_dump(gzread($h, 10));
echo "tell=";
var_dump(gztell($h));
echo "\nrewinding and try to move to before the start\n";
gzrewind($h);
echo "tell=".gztell($h)."\n";
echo "gzseek=";
var_dump(gzseek( $h, -5 ) );
echo "tell=";
var_dump(gztell($h));
var_dump(gzread($h, 10));
echo "tell=";
var_dump(gztell($h));
gzclose($h);
?>
Expected result:
----------------
move to the 40th byte
seek=int(0)
tell=40
try to move beyond the file
seek=int(-1)
tell=int(40)
string(10) "iny flying"
tell=int(50)
rewinding and try to move to before the start
tell=0
gzseek=int(-1)
tell=int(0)
string(10) "When you'r"
tell=int(10)
Actual result:
--------------
move to the 40th byte
seek=int(0)
tell=40
try to move beyond the file
seek=int(-1)
tell=bool(false)
string(0) ""
tell=bool(false)
rewinding and try to move to before the start
tell=0
gzseek=int(-1)
tell=bool(false)
string(10) "When you'r"
tell=int(9)
--
Edit bug report at http://bugs.php.net/?id=47171&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47171&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47171&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47171&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47171&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47171&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47171&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47171&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47171&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47171&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47171&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47171&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47171&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47171&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47171&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47171&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47171&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47171&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47171&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47171&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47171&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47171&r=mysqlcfg