php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64342 ZipArchive::Close returns false on large file trees
Submitted: 2013-03-03 18:42 UTC Modified: 2013-03-21 20:00 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: kolan_n at mail dot ru Assigned: ab (profile)
Status: Closed Package: Zip Related
PHP Version: 5.4.12 OS: Windows
Private report: No CVE-ID: None
 [2013-03-03 18:42 UTC] kolan_n at mail dot ru
Description:
------------
If you try to archive large file trees using ZipArchive you get false at ZipArchive::close().

ZipArchive::getStatusString says about "unknown error"

Test script:
---------------
install https://github.com/KOLANICH/PHP-Backuper
and dBug (or comment all "new dBug" in files, for example, with Notepad++)
download any archive, containing "large" tree, for example Drupal, and unpack it

write
<?
require_once("Backuper.php");
$b=new Backuper(
array(
'backup'=>array(
"FileTree"=>array(
"unpackedArchivePath"
)
)
)
);
$b->makeBackup();
?>
and launch

you will see that it doesn't work

the problem is on the https://github.com/KOLANICH/PHP-Backuper/blob/master/Backuper.php#L136 , $this->zip->close() returns false and the files would not be archivated.

Expected result:
----------------
$this->zip->close() returns true and the files are archivated

Actual result:
--------------
$this->zip->close() returns false and the files are not archivated

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-12 13:25 UTC] kolan_n at mail dot ru
Unknown error 55703736
 [2013-03-21 18:17 UTC] ab@php.net
It's usually not very handy to debug big scripts. It would rock if you could extract a small snippet representing the wrong behavior.
 [2013-03-21 18:17 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2013-03-21 18:34 UTC] kolan_n at mail dot ru
-Status: Feedback +Status: Open
 [2013-03-21 18:34 UTC] kolan_n at mail dot ru
I replaced this with PHAR and had found a bug in my script - it tryed to archivate a file which is not present beacuse of some errors in hash calculation (used instead of inode in windows).

But the error message should be understandable. It should not be "Unknown error 55703736" it should be "File not found". Also it will be good to add file existence check to ZipArchive::addFile implementation.

Now I am using phar but found some bug in its implementation : if there is .gz in the filename (in the middle of it), the archive type is set to tar.gz regardless of the flags.
 [2013-03-21 18:43 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2013-03-21 18:43 UTC] pajoye@php.net
Define large files tree. How many entries? No matter the platform, each folder 
can have a files amount limit, or a limit of file handles per process. 

It is pretty easy to create to a small script, create a zip objects, add as many 
files you need to it (from addFromString for example), close it :)

About the error code, mind to show a small code to reproduce it? or is it only a 
file not found on add? addFile uses to check file existences, but only on the 
method call. If the file disappears between add and close, the close method may 
file (compression and co is done on close).
 [2013-03-21 19:29 UTC] kolan_n at mail dot ru
-Status: Feedback +Status: Closed
 [2013-03-21 19:29 UTC] kolan_n at mail dot ru
>addFile uses to check file existences
https://github.com/php/php-src/blob/master/ext/zip/php_zip.c#L1797
https://github.com/php/php-src/blob/master/ext/zip/php_zip.h#L51
https://github.com/php/php-src/blob/642721b38a9c5ebf336c81027c0dafd6f9246bd6/main/fopen_wrappers.c#L314

It only checks wheither dir exists, but there is no checks for file existence

Phar::addFile makes this check, ZipArchive::addFile doesn't.
 [2013-03-21 20:00 UTC] pajoye@php.net
expand_filepath should do that check, ab, can you check that please? or we can use 
realpath in this case, which does check everything.
 [2013-03-21 20:00 UTC] pajoye@php.net
-Status: Closed +Status: Assigned -Assigned To: +Assigned To: ab
 [2013-04-10 18:52 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2013-04-10 18:52 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=968ae4a56a08587d73f81f30a0d57fbd109e4cf4
Log: Fixed bug #64342 ZipArchive::addFile() has to check for file existence
 [2013-04-11 06:47 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=330070
Log: Fixed bug #64342 ZipArchive::addFile() has to check for file existence
 [2014-10-07 23:19 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=968ae4a56a08587d73f81f30a0d57fbd109e4cf4
Log: Fixed bug #64342 ZipArchive::addFile() has to check for file existence
 [2014-10-07 23:30 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=968ae4a56a08587d73f81f30a0d57fbd109e4cf4
Log: Fixed bug #64342 ZipArchive::addFile() has to check for file existence
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC