Bug #47171 [Opn->Fbk]: Incorrect tell values when trying to seek beyond file range
| From: | cmb@php.net | Date: | Fri, 03 Apr 2020 11:45:30 +0000 |
| Subject: | Bug #47171 [Opn->Fbk]: Incorrect tell values when trying to seek beyond file range | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226423@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=47171&edit=1
ID: 47171
Updated by: cmb@php.net
Reported by: d_kelsey at uk dot ibm dot com
Summary: Incorrect tell values when trying to seek beyond
file range
-Status: Open
+Status: Feedback
Type: Bug
Package: Zlib related
Operating System: *
PHP Version: 5.*, 6CVS (2009-01-21)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Seeking to a negative position should indeed fail (and subsequent
telling should return false). However, seeking to a position
beyond the end of the file should work like for plain files; in
this case the file pointer should be advanced, and that should be
reflected when telling.
Anyhow, this issue appears to have been fixed in the meantime
(possibly it was a zlib issue), or can anybody still reproduce
this with any of the actively supported PHP versions[1]?
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2009-01-21 07:36:09] d_kelsey at uk dot ibm dot com
The problem still exists in the latest windows snapshot for php 5.2
------------------------------------------------------------------------
[2009-01-20 17:25:01] d_kelsey at uk dot ibm dot com
The provided test only covers the read scenario, but similar issues result when opening a zlib
stream for write as well.
------------------------------------------------------------------------
[2009-01-20 17:24:00] d_kelsey at uk dot ibm dot com
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 this bug report at https://bugs.php.net/bug.php?id=47171&edit=1