mirror of
https://github.com/php/php-src.git
synced 2026-03-27 01:32:22 +01:00
Merge branch 'PHP-5.6'
* PHP-5.6: Fix #70322: ZipArchive::close() doesn't indicate errors
This commit is contained in:
@@ -1495,6 +1495,7 @@ static ZIPARCHIVE_METHOD(close)
|
||||
struct zip *intern;
|
||||
zval *self = getThis();
|
||||
ze_zip_object *ze_obj;
|
||||
int err;
|
||||
|
||||
if (!self) {
|
||||
RETURN_FALSE;
|
||||
@@ -1504,7 +1505,8 @@ static ZIPARCHIVE_METHOD(close)
|
||||
|
||||
ze_obj = Z_ZIP_P(self);
|
||||
|
||||
if (zip_close(intern)) {
|
||||
if (err = zip_close(intern)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, zip_strerror(intern));
|
||||
zip_discard(intern);
|
||||
}
|
||||
|
||||
@@ -1513,7 +1515,11 @@ static ZIPARCHIVE_METHOD(close)
|
||||
ze_obj->filename_len = 0;
|
||||
ze_obj->za = NULL;
|
||||
|
||||
RETURN_TRUE;
|
||||
if (!err) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
29
ext/zip/tests/bug70322.phpt
Normal file
29
ext/zip/tests/bug70322.phpt
Normal file
@@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
Bug #70322 (ZipArchive::close() doesn't indicate errors)
|
||||
--DESCRIPTION--
|
||||
We want to test whether ZipArchive::close() returns FALSE and raises a warning
|
||||
on failure, so we force the failure by adding a file to the archive, which we
|
||||
delete before closing.
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('zip')) die('skip requires zip extension');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$zipfile = __DIR__ . '/bug70322.zip';
|
||||
$textfile = __DIR__ . '/bug70322.txt';
|
||||
touch($textfile);
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($zipfile, ZipArchive::CREATE);
|
||||
$zip->addFile($textfile);
|
||||
unlink($textfile);
|
||||
var_dump($zip->close());
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
// we don't expect the archive to be created, but clean up just in case...
|
||||
@unlink(__DIR__ . '/bug70322.zip');
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: ZipArchive::close(): Read error: No such file or directory in %s%ebug70322.php on line %d
|
||||
bool(false)
|
||||
@@ -63,7 +63,8 @@ $sb = $zip->statIndex(1);
|
||||
var_dump($sb);
|
||||
$sb = $zip->statIndex(2);
|
||||
var_dump($sb);
|
||||
$zip->close();
|
||||
// suppress irrelevant error message:
|
||||
@$zip->close();
|
||||
unset($zip);
|
||||
|
||||
if (file_exists($file)) {
|
||||
|
||||
Reference in New Issue
Block a user