Bug #80544 [Fbk->NoF]: zip close failure with no errors
| From: | php-bugs at lists dot php dot net | Date: | Sun, 03 Jan 2021 04:22:08 +0000 |
| Subject: | Bug #80544 [Fbk->NoF]: zip close failure with no errors | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231342@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80544&edit=1
ID: 80544
Updated by: php-bugs@lists.php.net
Reported by: peter dot mlich at volny dot cz
Summary: zip close failure with no errors
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Zip Related
Operating System: win10
PHP Version: 7.2.6
Assigned To: cmb
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2020-12-22 15:37:21] cmb@php.net
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 http://www.php.net/downloads.php
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.
------------------------------------------------------------------------
[2020-12-22 15:11:12] peter dot mlich at volny dot cz
Description:
------------
---
From manual page: https://php.net/ziparchive.close
---
Some files add to zip from disk create bug. May be some file, with change time 1979 (or 1917?), when
create time is 2019. And sometime work correctly. I cant find more, because write 0 errors. No write
error in addFile phase, no write error in $zip->close. Write only warning with "No
Error" text.
I have min 1 file, but, i replace it from older program, not save for testing, sorry. image jpeg
from adobe ilustrator, logo EU project.
I test, do file by file to found problem file (50%, 25%, 12,5%...). When i replace, archive is
created by zip-close.
I this file may be created from word document, save image from doc to file. Or extract by Far / Rar
from xdocfile. Or somebody sand me by mail for project.
Workable file have info
projekt-logo.jpg
22 12 2020 23:00:00,000 last write time
17 12 2020 09:27:00,784 create
22 12 2020 15:24:54,876 last access
17 12 2020 09:27:01,501 change
Ad. ilustrator cs5.1
create 7.4.2016 22:21
title = EU OP VVV MSMT Angl.
(= europan operation program science... MSMT agenture, english)
1559x346 220 dpi
code:
var_dump($zip);
$success = $zip->close();
var_dump(base64_encode(file_get_contents($filename)));
object(ExtendedZip)#36 (5) { ["status"]=> int(0) ["statusSys"]=> int(0)
["numFiles"]=> int(298) ["filename"]=> string(45)
"C:\Users\peter\AppData\Local\Temp\memF3A1.tmp" ["comment"]=> string(0)
"" }
// $success = false
Warning: ZipArchive::close(): Read error: No error in
C:\xampp\htdocs\www\ev2c_hraward\inc\class_export_program.php on line XXX
string(0) ""
PHP Version 7.2.6
System Windows NT DESKTOP-J96VK8S 10.0 build 19041 (Windows 10) i586
Build Date May 23 2018 20:26:19
Compiler MSVC15 (Visual C++ 2017)
Architecture x86
Server API Apache 2.0 Handler
PHP API 20170718
PHP Extension 20170718
Zend Extension 320170718
Zend Extension Build API320170718,TS,VC15
PHP Extension Build API20170718,TS,VC15
Apache Version Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.6
Apache API Version 20120211
Test script:
---------------
<?php
global $III, $III_max, $FF;
/*
public function exportDb($filename_prefix="hraward_zaloha")
{
$zipname = $filename_prefix.'_'.date('Y-m-d-H-i-s',
time()).'.zip'; // tady byla na zacatku '.' + name, nevim proc | $zipname =
'./tmp/archive_'.$time.'.zip';
$addfiles = array();
$addfiles['inc/cfg_inc.php'] = preg_replace('~\=\>
\'[^\']+\'~', '=> \'\'',
file_get_contents('./inc/cfg_inc.php'));
$addfiles['sql/mysql_dump.sql'] = $this->SQL->exportDb();
$skipdirs = array(
'tmp', // trash tmp
'error', 'stats', // trash isp-config
'form/old', 'inc/x', // trash localhost dirs
'htx.1', 'htx.2', 'htx.3',
'old', 'x', 'x-upl',
'zadani',
'zal'
//'sql' // trash localhost dirs + add mysql dump in before code, sql tam nech, jsou
tam install.sql
);
$sizelimit = 100 * 1024 * 1024; // ~100M
//echo '<pre>';
ExtendedZip::zipTree('.', $zipname, ZipArchive::CREATE, '', $addfiles,
$skipdirs, $sizelimit);
// ExtendedZip::zipTree('./css', $zipname, ZipArchive::CREATE, '', $addfiles);
//$mime = "application/zip"; //application/x-gzip
//header( "Content-Type: " . $mime );
//header( 'Content-Disposition: attachment; filename="' . $filename .
'"' );
exit();
}
*/
class ExtendedZip extends ZipArchive
{
public function colorize($color, $str)
{
return '<span
style="color:#'.$color.'">'.$str.'</span>';
}
// Member function to add a whole file system subtree to the archive
public function addTree($dirname='', $localname = '', $skipdirs=array())
{
global $III, $III_max;
if ($localname)
{
$this->addEmptyDir($localname);
echo $this->colorize('08C', 'NEW'.' '.$localname.'/');
$III++; if ($III==$III_max) { if ($list) echo implode("<br>",
$list)."<br>"; $success = $this->close();
var_dump(base64_encode(file_get_contents($FF))); exit();}
}
$this->_addTree($dirname, $localname, $skipdirs);
}
// Internal function, to recurse
protected function _addTree($dirname='', $localname='', &$skipdirs=array())
{
global $III, $III_max, $FF;
$list = array();
$dir = opendir($dirname);
while ($filename = readdir($dir))
{
// Discard . and ..
if ($filename == '.' || $filename == '..') // || $filename ==
'.htaccess'
{
continue;
}
// Proceed according to type
$path = $dirname . '/' . $filename;
$localpath = $localname ? ($localname . '/' . $filename) : $filename;
if (is_dir($path))
{
// Directory: add & recurse
// skip dirs - remove
if (in_array($filename, $skipdirs))// || in_array(substr($filename, 2), $skip)) //
"./dirname" -> "dirname"
{
$list[] = $this->colorize('08C', 'skipped'.'
'.$filename.'/');
$III++; if ($III==$III_max) { if ($list) echo implode("<br>",
$list)."<br>"; $success = $this->close();
var_dump(base64_encode(file_get_contents($FF))); exit();}
continue;
}
$success = $this->addEmptyDir($localpath);
$list[] = $this->colorize($success?'000':'f00', var_export($success,1).'
'.$localpath.'/');
$III++; if ($III==$III_max) { if ($list) echo implode("<br>",
$list)."<br>"; $success = $this->close();
var_dump(base64_encode(file_get_contents($FF))); exit();}
$this->_addTree($path, $localpath, $skipdirs);
}
elseif (is_file($path))
{
// File: just add
$success = $this->addFile($path, $localpath);
$list[] = $this->colorize($success?'000':'f00', var_export($success,1).'
'.$localpath);
$III++; if ($III==$III_max) { if ($list) echo implode("<br>",
$list)."<br>"; $success = $this->close();
var_dump(base64_encode(file_get_contents($FF))); exit();}
}
}
echo implode("<br>", $list)."<br>"; // br navic kvuli subdirs
closedir($dir);
}
public static function zipTree($dirname, $zipFilename='archive', $flags = 0, $localname =
'', $addfiles=array(), $skipdirs=array(), $sizelimit=104857600) //$sizelimit = 100 * 1024
* 1024 =~ 100M
{
global $III, $III_max, $FF;
$III = 0;
$III_max = 300; // 130
// $limit = 100 * 1024 * 1024; // ~100M
// $path = "php://memory/maxmemory:$limit";
// $filename = "/tmp/xxx.zip";
//$path = sys_get_temp_dir();
$path = "php://temp/maxmemory:$sizelimit";
$filename = tempnam($path, 'memoryZipHraward');
$FF = $filename;
var_dump('filename', $filename);
$zip = new self();
$opened = $zip->open($filename, $flags);
//die("aaa");
if( $opened !== true )
{
die("cannot open {$filename} for writing.");
}
// add files in dirs from disk, recursive
$zip->addTree($dirname, $localname, $skipdirs);
// add files from content (additional files)
if (is_array($addfiles))
{
foreach($addfiles as $localname=>$content)
{
$success = $zip->addFromString($localname, $content);
echo var_export($success,1).' '.$localname.'<br>';
//var_dump(array($success, $localname)); echo '<br>';
}
}
var_dump($zip);
$success = $zip->close();
echo '<br>';
echo '<br>5. '; var_dump(base64_encode(file_get_contents($filename)));
$download = true;
$download = false; echo '<hr>filesize = '.filesize($filename).', numFiles =
'. $zip->numFiles.'<hr>';
if ($download==true)
{
ob_clean();
header("Content-Description: File Transfer");
header('Content-type: application/zip');
header("Content-Length: " . filesize($filename));
header('Content-Disposition: attachment;
filename="'.$zipFilename.'"');
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
echo file_get_contents($filename);
unlink($filename);
exit;
}
else {
unlink($filename);
}
// echo stream_get_contents($zip);
// if (file_exists($filename)) {
// unlink($filename);
// readfile($filename);
}
}
/*
$filename_prefix="hraward_zaloha";
$zipname = $filename_prefix.'_'.date('Y-m-d-H-i-s',
time()).'.zip'; // tady byla na zacatku '.' + name, nevim proc | $zipname =
'./tmp/archive_'.$time.'.zip';
$addfiles = array();
$addfiles['inc/cfg_inc.php'] = preg_replace('~\=\>
\'[^\']+\'~', '=> \'\'',
file_get_contents('./inc/cfg_inc.php'));
// $addfiles['sql/mysql_dump.sql'] = $this->SQL->exportDb();
$skipdirs = array(
'tmp', // trash tmp
'error', 'stats', // trash isp-config
'form/old', 'inc/x', // trash localhost dirs
'htx.1', 'htx.2', 'htx.3',
'old', 'x', 'x-upl',
'zadani',
'zal'
//'sql' // trash localhost dirs + add mysql dump in before code, sql tam nech, jsou
tam install.sql
);
$sizelimit = 100 * 1024 * 1024; // ~100M
//echo '<pre>';
ExtendedZip::zipTree('.', $zipname, ZipArchive::CREATE, '', $addfiles,
$skipdirs, $sizelimit);
// ExtendedZip::zipTree('./css', $zipname, ZipArchive::CREATE, '', $addfiles);
//$mime = "application/zip"; //application/x-gzip
//header( "Content-Type: " . $mime );
//header( 'Content-Disposition: attachment; filename="' . $filename .
'"' );
//exit();
*/
Expected result:
----------------
readable file.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80544&edit=1