php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47171 Incorrect tell values when trying to seek beyond file range
Submitted: 2009-01-20 17:24 UTC Modified: 2020-04-12 04:22 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: d_kelsey at uk dot ibm dot com Assigned: cmb (profile)
Status: No Feedback Package: Zlib related
PHP Version: 5.*, 6CVS (2009-01-21) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
28 - 12 = ?
Subscribe to this entry?

 
 [2009-01-20 17:24 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-20 17:25 UTC] 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-21 07:36 UTC] d_kelsey at uk dot ibm dot com
The problem still exists in the latest windows snapshot for php 5.2
 [2020-04-03 11:45 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-04-03 11:45 UTC] cmb@php.net
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>
 [2020-04-12 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC