php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #39874 gztell returns incorrect file pointer number
Submitted: 2006-12-18 18:36 UTC Modified: 2007-08-17 11:17 UTC
From: sramage at nucleuslabs dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.4.4 OS: FREEBSD 5
Private report: No CVE-ID: None
 [2006-12-18 18:36 UTC] sramage at nucleuslabs dot com
Description:
------------
The GZTELL function returns the gz file pointer as the uncompressed data byte position not the real file pointer location when writing to a file.

I am not sure if this is a bug or just the way it is. but it doesn't really make sense so I am reporting it.

The example is very simple and clear.

just use any text file that is 2 MB or bigger in length to recreate this bug

We use the recommened php ini with the following changes:

memory_limit = 32M
error_reporting  =  E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR	
upload_max_filesize = 10Mb
session.cookie_lifetime = 0
session.cookie_path = /
session.gc_probability = 1
session.gc_divisor = 1
session.gc_maxlifetime = 3600
session.entropy_length = 16
session.entropy_file = /dev/urandom

modules:

'./configure' '--enable-versioning' '--enable-memory-limit' '--with-layout=GNU' '--disable-all' '--with-regex=php' '--with-pcre-regex' '--with-pear' '--enable-ftp' '--with-openssl=/usr/local/ssl' '--enable-ftp' '--with-mysql=/usr/local/mysql' '--enable-overload' '--enable-session' '--enable-xml' '--with-zlib=yes' '--with-apxs=/usr/local/apache/bin/apxs' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php' '--enable-mbstring=all' '--enable-track-vars' '--enable-force-cgi-redirect' '--with-gettext' '--with-pspell' 



Reproduce code:
---------------
<?
//Example: 
//some_file.sql plain text file - filesize = 2,048,000 bytes

$text_fp=fopen('some_file.sql','r');
$gz_fp=gzopen('some_file.sql.gz','wb9');
while(!feof($text_fp)){
    gzwrite($gz_fp,fread($text_fp,655360));
}
fclose($text_fp);
echo "gztell = ".gztell($gz_fp)."<BR>\n";
gzclose($gz_fp);
echo "filesize = ".filesize('some_file.sql.gz')."<BR>\n";
?>






Expected result:
----------------
gztell = 249264 
filesize = 249264

(or something closer to the actual file pointer position in the gz file)




Actual result:
--------------
gztell = 2048000
filesize = 249264

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-19 15:14 UTC] tony2001@php.net
gzread() and gztell() operate on _uncompressed_ bytes, that should be mentioned in gztell() docs (already done for gzread()).
Reclassified as docu problem.
 [2006-12-20 17:05 UTC] sramage at nucleuslabs dot com
I tried using ftell and it returned the exact same result as gztell.

If ftell returns the _uncompressed_ byte pointer position, wouldn't that make the gztell function pointless?

Shouldn't one of these functions tell the *actual* file pointer position?

I was trying to create specific size GZ files using this function as a measuring device I have found another way that is inefficient but it works (we're only talking about 10 seconds over 100MB so not a big deal just wasn't sure about the actual difference between ftell and gztell or if they just a designed to behave a certain way when they encounter compressed/uncompressed data). 

hopefully this help with the documentation.
Thanks!
 [2007-08-17 11:17 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"its offset into the uncompressed file stream"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 20:01:27 2025 UTC