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
}
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) {
--- /dev/null
+--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).)*