php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57357 Images files added with ZipArchive::addFile corrupt
Submitted: 2006-11-08 13:07 UTC Modified: 2008-01-15 04:17 UTC
From: luc_azer at yahoo dot fr Assigned: pajoye (profile)
Status: Closed Package: zip (PECL)
PHP Version: 5.2.0 OS: XP
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:
Package:
Bug Type:
Summary:
From: luc_azer at yahoo dot fr
New email:
PHP Version: OS:

 

 [2006-11-08 13:07 UTC] luc_azer at yahoo dot fr
Description:
------------
I want to add an image files (logo.gif) to a newly created and not yet existing zip-archive by using the method 'ZipArchive::addFile'.

WinRAR 3.61 reports Diagnostic messages:
CRC failed in logo.gif
The file is corrupt

Winzip 9.0: invalid compressed data to inflate.

The result come from a modify version of the create.php example

Reproduce code:
---------------
<?php
error_reporting(E_ALL);
if (!extension_loaded('zip')) {
    dl('zip.so');
}
$thisdir = dirname(__FILE__);
unlink("./test112.zip");
$zip = new ZipArchive();
$filename = "./test112.zip";

if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
	exit("cannot open <$filename>\n");
} else {
	echo "file <$filename> OK\n";
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/logo.gif","/logo.gif");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
unset($zip);
?>

Expected result:
----------------
I expected newly created zip-archive with the readable image inside.

Actual result:
--------------
Impossible to read the image inside the zip file.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 13:17 UTC] pierre dot php at gmail dot com
Zip Package, not website.

Please try using 5.2.0 (final not RC) or a snapshot from pecl4win.php.net.
 [2006-11-09 04:13 UTC] luc_azer at yahoo dot fr
I try using the last php_zip.dll from pecl4win.php.net.
It's always impossible to read the image inside the zip file.

phpinfo() give me the following information:

PHP Version 5.2.0
...
zip
Zip 	enabled
Extension Version 	$Id: php_zip.c,v 1.85 2006/11/01 22:51:36 pajoye Exp $
Zip version 	@PACKAGE_VERSION@
Libzip version 	0.7.1
 [2006-11-09 20:39 UTC] pierre dot php at gmail dot com
I tried with many images and other binary files without getting any single corrupted archives. Can you post a link to the image?

Also can you try using the bundled version in 5.2.0 (or 5.2.x snapshot) and not using a dll from pecl4win.php.net?
 [2006-11-10 02:58 UTC] luc_azer at yahoo dot fr
I get the same result with the image logo.gif from "http://www.google.com/intl/en_ALL/images/logo.gif"
 [2006-11-10 05:06 UTC] luc_azer at yahoo dot fr
I try with full PHP 5.2 from php.net.
I try with the distribution for Windows of XAMPP 1.5.4a (PHP 5.1.6).
I try with the distribution for Windows of Wamp 1.6.6 (PHP 5.2.0).

The behavour is the same.It's always impossible to read the image inside the zip file.

However I try to use php from command line and the zip file is correct!!!
>php.exe create.php
 [2006-11-10 07:39 UTC] pierre dot php at gmail dot com
Are you sure you successfully rewrite the archive? Use:

if (!$zip->open($filename, ZIPARCHIVE::OVERWRITE)) 

to start a fresh new archive (it is erased and then created).

What are you using as webserver/SAPI?

On y arrivera :)
 [2006-11-10 08:27 UTC] luc_azer at yahoo dot fr
I try "if (!$zip->open($filename, ZIPARCHIVE::OVERWRITE)) " and it's always impossible to read the image inside
the zip file.


I'm sure I successfully rewrite the archive because I made a manual delete of the archive.


I use apache 2.0.59 (win32) webserver.

On y arrivera ?
 [2006-11-10 10:22 UTC] pierre dot php at gmail dot com
Ok, it seems that a friend found the issue, please try using:

$zip->addFile($thisdir . "/logo.gif","logo.gif");
 [2006-11-10 10:24 UTC] pierre dot php at gmail dot com
wrong, it fails as well. I have to check in debug mode under apache2. I will do it next week.
 [2006-11-11 14:27 UTC] pierre dot php at gmail dot com
I can reproduce the bug, finally (with or without image files, using addFile or addString). But I still have no idea what is going wrong. The same code works everywhere else (apache2 unix, cli, cgi)
 [2006-11-12 09:37 UTC] luc_azer at yahoo dot fr
Congratulations ! You can reproduce the bugs. Can I help you with other test?
 [2006-11-12 09:55 UTC] pierre dot php at gmail dot com
Can you try this script? and give me the result?

<?php
error_reporting(E_ALL);
unlink("./a.zip");
$zip = new ZipArchive();
$filename = "./a.zip";

if (!$zip->open($filename, ZIPARCHIVE::OVERWRITE)) {
	exit("cannot open <$filename>\n");
} else {
	echo "file <$filename> OK\n";
}
$zip->addFromString("ma.txt", "0123456789");

var_dump($zip->close());
var_dump($zip);
 [2006-11-13 03:18 UTC] luc_azer at yahoo dot fr
The result of your script test is :

file <./a.zip> OK bool(true) object(ZipArchive)#1 (5) { ["status"]=>  int(0) ["statusSys"]=>  int(0) ["numFiles"]=>  int(0) ["filename"]=>  string(0) "" ["comment"]=>  string(0) "" }

Winzip 9.0 alert message when opening the archive:
Cannot open file:It does not  appear to be a valid archive
 [2006-11-15 11:26 UTC] pierre dot php at gmail dot com
I just commited a fix, it should fix it for all other SAPI (it works in CLI/CGI/Embed). Please try the next PHP 5.2 snapshot.
 [2006-11-15 12:12 UTC] luc_azer at yahoo dot fr
Must I try with only php_zip.dll from pecl4win.php.net.
or with the full PHP 5.2 from php.net.
 [2006-11-15 12:19 UTC] pierre dot php at gmail dot com
The 5.2. snapshots here:

http://snaps.php.net/

Wait the next builds (in 2h~). My commit was done after the current snapshot.
 [2006-11-16 09:37 UTC] luc_azer at yahoo dot fr
Now it works perfectly !
Thanks you.
For information what was the source of the bug?
 [2006-11-16 10:48 UTC] pierre dot php at gmail dot com
The problem is double. The source of it is a windows bug. It does not always respect the binary mode when passed to fopen(path,"rb") or "wb", or it is buggy (it seems taht many projects had the same issue, as they use the same trick to force the binary mode).

It works in CLI/CGI and embed because PHP forces the default to binary in these three SAPI, it does not force it in ISAPI, and apache2.

Thanks for your patience :)
 [2008-01-14 22:07 UTC] mathan at isakuratech dot com
Hi,

I can not make zip archive for image file.
Plz help me , How will u solve that?
 [2008-01-15 04:17 UTC] pierre dot php at gmail dot com
"I can not make zip archive for image file.
Plz help me , How will u solve that?"

The problem described in this bug is already fixed. If you have troubles to add files to an archive or to create an archive and you think it is a bug, please open a new bug.
 [2009-03-25 15:33 UTC] toxnico at gmail dot com
Thank you very much for this correction !
Nico
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC