[php-src] master: Fix GH-25360: ZipArchive assertion when error handler throws at shutdown (#25361)

From: Date: Thu, 26 Nov 2026 09:13:42 +0000
Subject: [php-src] master: Fix GH-25360: ZipArchive assertion when error handler throws at shutdown (#25361)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144204@lists.php.net to get a copy of this message
Author: lazerg (lazerg) Committer: Weilin Du (LamentXU123) Date: 2026-11-26T17:06:58+08:00 Commit: https://github.com/php/php-src/commit/3a82d70397bb8ab175b8e3688df4e53dbb083351 Raw diff: https://github.com/php/php-src/commit/3a82d70397bb8ab175b8e3688df4e53dbb083351.diff Fix GH-25360: ZipArchive assertion when error handler throws at shutdown (#25361) If zip_close() fails during shutdown and the warning handler throws, the bailout interrupts archive release after the refcount drops to zero. The object still points to the archive, so free_storage tries closing it again and hits an assertion. Catch bailouts from close warnings in php_zip_archive_release() and php_zipobj_close() and let the existing bailout path run after cleanup. The second guard also lets free_storage discard the libzip handle when the object destructor did not run. Closes #25361 Changed paths: A ext/zip/tests/gh25360.phpt M NEWS M ext/zip/php_zip.c Diff: diff --git a/NEWS b/NEWS index 47b729fab04c..50c3719a3ccf 100644 --- a/NEWS +++ b/NEWS @@ -280,6 +280,10 @@ PHP NEWS . Fixed a crash in XSLTProcessor::transformToDoc() when the return class cannot be instantiated. (Ilia Alshanetsky) +- Zip: + . Fixed bug GH-25360 (ZipArchive assertion when an error handler throws + on implicit close at shutdown). (lazerg) + 19 Nov 2026, PHP 8.6.0 - Core: diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 5baecfc18933..14ee1bf3b822 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -660,7 +660,11 @@ static bool php_zipobj_close(ze_zip_object *obj, zend_string **out_str) /* {{{ * archive->close = true; int err = zip_close(intern); if (err) { - php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern)); + zend_try { + php_error_docref(NULL, E_WARNING, "%s", zip_strerror(intern)); + } zend_catch { + archive->bailout_callback = true; + } zend_end_try(); /* Save error for property reader */ zip_error_t *ziperr = zip_get_error(intern); obj->err_zip = zip_error_code_zip(ziperr); @@ -1184,7 +1188,12 @@ bool php_zip_archive_release(php_zip_archive *archive) int err = zip_close(archive->za); if (err != 0) { if (!archive->bailout_callback) { - php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(archive->za)); + /* An error handler that throws during shutdown bails out. */ + zend_try { + php_error_docref(NULL, E_WARNING, "Cannot destroy the zip context: %s", zip_strerror(archive->za)); + } zend_catch { + archive->bailout_callback = true; + } zend_end_try(); } zip_discard(archive->za); } diff --git a/ext/zip/tests/gh25360.phpt b/ext/zip/tests/gh25360.phpt new file mode 100644 index 000000000000..51b297251ece --- /dev/null +++ b/ext/zip/tests/gh25360.phpt @@ -0,0 +1,31 @@ +--TEST-- +GH-25360 (Assertion failure when the error handler throws on the implicit close at shutdown) +--CREDITS-- +YuanchengJiang +--EXTENSIONS-- +zip +--FILE-- +<?php +$zip = new ZipArchive(); +$zip->open(__DIR__ . '/gh25360.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); +file_put_contents(__DIR__ . '/gh25360.txt', 'contents'); +$zip->addFile(__DIR__ . '/gh25360.txt', 'file.txt'); +unlink(__DIR__ . '/gh25360.txt'); +set_error_handler(function () { + throw new Exception('handler'); +}); +echo "Done\n"; +?> +--CLEAN-- +<?php +@unlink(__DIR__ . '/gh25360.zip'); +@unlink(__DIR__ . '/gh25360.txt'); +?> +--EXPECTF-- +Done + +Fatal error: Uncaught Exception: handler in %s:%d +Stack trace: +#0 [internal function]: {closure:%s:%d}(2, '%s', 'Unknown', 0) +#1 {main} + thrown in %s on line %d

« previous php.cvs (#144204) next »