Bug #80544 [NEW]: zip close failure with no errors

From: Date: Tue, 22 Dec 2020 15:11:13 +0000
Subject: Bug #80544 [NEW]: zip close failure with no errors
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231218@lists.php.net to get a copy of this message
From: peter dot mlich at volny dot cz Operating system: win10 PHP version: 7.3.25 Package: Zip Related Bug Type: Bug Bug description:zip close failure with no errors 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 bug report at https://bugs.php.net/bug.php?id=80544&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80544&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80544&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80544&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80544&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80544&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80544&r=support Expected behavior: https://bugs.php.net/fix.php?id=80544&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80544&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80544&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80544&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80544&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80544&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80544&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80544&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80544&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80544&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80544&r=mysqlcfg

« previous php.bugs (#231218) next »