com php-src: Fix bug #76524 - ZipArchive memory leak: ext/zip/php_zip.c ext/zip/tests/bug76524.phpt
| From: | Anatol Belski | Date: | Tue, 10 Jul 2018 09:18:37 +0000 |
| Subject: | com php-src: Fix bug #76524 - ZipArchive memory leak: ext/zip/php_zip.c ext/zip/tests/bug76524.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102508@lists.php.net to get a copy of this message | ||
Commit: 08f08858f3bc62fac9150ca5b669df060b5af5a5
Author: timurib <timok@ya.ru> Mon, 25 Jun 2018 14:14:26 +0300
Committer: Anatol Belski <ab@php.net> Tue, 10 Jul 2018 11:18:37 +0200
Parents: a820aab9da3389e3df5711306d05660d8bf35ff0
Branches: PHP-7.1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=08f08858f3bc62fac9150ca5b669df060b5af5a5
Log:
Fix bug #76524 - ZipArchive memory leak
Bugfix #76524: Free up zip internal state and adjust the tests for Windows
Bugfix #76524: Fix possible use after free for libzip 1.3.1
Bugfix #76524: Make the test independent of platform
Bugs:
https://bugs.php.net/76524
Changed paths:
M ext/zip/php_zip.c
A ext/zip/tests/bug76524.phpt
Diff:
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index ade0b99..cdf77f2 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1003,10 +1003,13 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
}
if (intern->za) {
if (zip_close(intern->za) != 0) {
+#if LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR == 3 && LIBZIP_VERSION_MICRO
== 1
+ php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s",
"zip_close have failed");
+#else
php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s",
zip_strerror(intern->za));
- return;
+ zip_discard(intern->za);
+#endif
}
- intern->za = NULL;
}
if (intern->buffers_cnt>0) {
diff --git a/ext/zip/tests/bug76524.phpt b/ext/zip/tests/bug76524.phpt
new file mode 100644
index 0000000..f28bfc1
--- /dev/null
+++ b/ext/zip/tests/bug76524.phpt
@@ -0,0 +1,21 @@
+--TEST--
+ZipArchive Bug #76524 (memory leak with ZipArchive::OVERWRITE flag and empty archive)
+--SKIPIF--
+<?php
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+
+$filename = __DIR__ . '/nonexistent.zip';
+
+$zip = new ZipArchive();
+$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
+echo 'ok';
+
+/* Zip-related error messages depend on platform and libzip version,
+ so the regex is used to check that Zend MM does NOT show warnings
+ about leaks: */
+?>
+--EXPECTREGEX--
+ok((?!memory leaks detected).)*