From b76f7e3173abb1682dcb0269c4d8c9fb8b399d93 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:40:38 +0200 Subject: [PATCH] Fix GH-18431: Registering ZIP progress callback twice doesn't work Libzip already cleans up the previous callback, so when that means: 1. The callback zval being already copied over the previous one causes libzip to clean up the new callback object. This is the root cause. 2. Our own code to clean the old callback is redundant. --- ext/zip/php_zip.c | 10 ++-------- ext/zip/tests/gh18431.phpt | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 ext/zip/tests/gh18431.phpt diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 45b83aeae63bc..388b3485cbd94 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -3048,14 +3048,11 @@ PHP_METHOD(ZipArchive, registerProgressCallback) obj = Z_ZIP_P(self); - /* free if called twice */ - _php_zip_progress_callback_free(obj); - /* register */ - ZVAL_COPY(&obj->progress_callback, &fci.function_name); if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) { RETURN_FALSE; } + ZVAL_COPY(&obj->progress_callback, &fci.function_name); RETURN_TRUE; } @@ -3093,14 +3090,11 @@ PHP_METHOD(ZipArchive, registerCancelCallback) obj = Z_ZIP_P(self); - /* free if called twice */ - _php_zip_cancel_callback_free(obj); - /* register */ - ZVAL_COPY(&obj->cancel_callback, &fci.function_name); if (zip_register_cancel_callback_with_state(intern, _php_zip_cancel_callback, _php_zip_cancel_callback_free, obj)) { RETURN_FALSE; } + ZVAL_COPY(&obj->cancel_callback, &fci.function_name); RETURN_TRUE; } diff --git a/ext/zip/tests/gh18431.phpt b/ext/zip/tests/gh18431.phpt new file mode 100644 index 0000000000000..d4eb89c36c6bb --- /dev/null +++ b/ext/zip/tests/gh18431.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-18431 (Registering ZIP progress callback twice doesn't work) +--EXTENSIONS-- +zip +--FILE-- +open($file, ZIPARCHIVE::CREATE); +$zip->registerProgressCallback(0.5, $callback); +$zip->registerProgressCallback(0.5, $callback); +$zip->addFromString('foo', 'entry #1'); +?> +--CLEAN-- + +--EXPECT-- +float(0) +float(1)