|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37335 zip_entry_read handling of null byte
Submitted: 2006-05-05 21:15 UTC Modified: 2010-12-20 14:51 UTC
From: humbads at alum dot mit dot edu Assigned: pajoye (profile)
Status: Not a bug Package: Zip Related
PHP Version: 4.4.2 OS: FreeBSD 4.7 RELEASE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: humbads at alum dot mit dot edu
New email:
PHP Version: OS:


 [2006-05-05 21:15 UTC] humbads at alum dot mit dot edu
When using zip_entry_read to decompress a zip entry containing a null byte, the function only returns data up to the first null byte in the decompressed file.  Bug does not occur on PHP 5.1.2 for Windows XP.

Reproduce code:
// contains one file with a null byte in the middle
$zipfile = zip_open("");
$zipentry = zip_read($zipfile);
zip_entry_open($zipfile, $zipentry);

$content = zip_entry_read($zipentry, zip_entry_filesize($zipentry));
print "filesize: ".filesize("onejpg.jpg")."\n";
print "variable: ";



Expected result:
var_dump should show a string with the same length as the file size.

To download and onejpg.jpg, go here:

Actual result:
var_dump only shows length 4, which is the length up to the null byte.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-05 21:43 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read for *NIX and for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

Which version(s) of the zip package do you use? 
 [2006-05-05 21:44 UTC]
Sorry for the previous comment, a wrong snippet was selected.

My question is only: which version(s) of the zip package do you use?
 [2006-05-05 22:28 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

I cannot reproduce your problen with the latest Zip release. Your zip works with php 4.4 and 5.1.x. I can read and extract the image.

I also recommend to use the new API with php 5.1+. It is more efficient and you can extract directly to the disk.

You can fetch the latest release from the PECL site:

If you still have troubles, please reopen this bug.
 [2006-05-06 02:15 UTC] humbads at alum dot mit dot edu
The version of pecl-zip seems to be 1.2.1 based on the Makefile in the ports directory.  I'd prefer not to upgrade to PHP 5.1 at this time, and I am extracting the zip contents into a database, so it has to happen in memory. I'll try the latest PECL zip package.
 [2006-05-06 02:17 UTC] humbads at alum dot mit dot edu
Just noticed the changelog for pecl-zip, and this bug has been fixed since version 1.2.3 -- "#7214, use binary safe string as return value". Sorry for the trouble.
 [2006-05-06 03:37 UTC] humbads at alum dot mit dot edu
Confirmed.  After updating to the latest 1.3.1 by running pkg_add for gnu-autoconf, gnu-automake, and gnu-libtool, adding a symbolic link "autoconf" to /usr/local/bin/autoconf529, and then running "pear install", the error went away.
 [2010-12-20 14:51 UTC]
-Package: ZZiplib Related +Package: Zip Related
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 23 15:05:35 2020 UTC