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: 2009-04-27 16:10 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:
Status: Open Package: Zlib related
PHP Version: 5.*, 6CVS (2009-01-21) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: d_kelsey at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 10:01:26 2019 UTC