Skip to content

Commit b066ac0

Browse files
committed
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. Closes GH-18432.
1 parent a91d913 commit b066ac0

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
- Standard:
1515
. Fixed bug GH-17403 (Potential deadlock when putenv fails). (nielsdos)
1616

17+
- Zip:
18+
. Fixed bug GH-18431 (Registering ZIP progress callback twice doesn't work).
19+
(nielsdos)
20+
1721
08 May 2025, PHP 8.3.21
1822

1923
- Core:

ext/zip/php_zip.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,14 +3048,11 @@ PHP_METHOD(ZipArchive, registerProgressCallback)
30483048

30493049
obj = Z_ZIP_P(self);
30503050

3051-
/* free if called twice */
3052-
_php_zip_progress_callback_free(obj);
3053-
30543051
/* register */
3055-
ZVAL_COPY(&obj->progress_callback, &fci.function_name);
30563052
if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) {
30573053
RETURN_FALSE;
30583054
}
3055+
ZVAL_COPY(&obj->progress_callback, &fci.function_name);
30593056

30603057
RETURN_TRUE;
30613058
}
@@ -3093,14 +3090,11 @@ PHP_METHOD(ZipArchive, registerCancelCallback)
30933090

30943091
obj = Z_ZIP_P(self);
30953092

3096-
/* free if called twice */
3097-
_php_zip_cancel_callback_free(obj);
3098-
30993093
/* register */
3100-
ZVAL_COPY(&obj->cancel_callback, &fci.function_name);
31013094
if (zip_register_cancel_callback_with_state(intern, _php_zip_cancel_callback, _php_zip_cancel_callback_free, obj)) {
31023095
RETURN_FALSE;
31033096
}
3097+
ZVAL_COPY(&obj->cancel_callback, &fci.function_name);
31043098

31053099
RETURN_TRUE;
31063100
}

ext/zip/tests/gh18431.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-18431 (Registering ZIP progress callback twice doesn't work)
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
$file = __DIR__ . '/gh18431.zip';
8+
$callback = var_dump(...);
9+
$zip = new ZipArchive;
10+
$zip->open($file, ZIPARCHIVE::CREATE);
11+
$zip->registerProgressCallback(0.5, $callback);
12+
$zip->registerProgressCallback(0.5, $callback);
13+
$zip->addFromString('foo', 'entry #1');
14+
?>
15+
--CLEAN--
16+
<?php
17+
$file = __DIR__ . '/gh18431.zip';
18+
@unlink($file);
19+
?>
20+
--EXPECT--
21+
float(0)
22+
float(1)

0 commit comments

Comments
 (0)