Skip to content

Commit a7cc447

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-18431: Registering ZIP progress callback twice doesn't work
2 parents d36b029 + 5b8db66 commit a7cc447

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ext/zip/php_zip.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,14 +3050,11 @@ PHP_METHOD(ZipArchive, registerProgressCallback)
30503050
RETURN_THROWS();
30513051
}
30523052

3053-
/* free if called twice */
3054-
php_zip_progress_callback_free(obj);
3055-
30563053
/* register */
3057-
zend_fcc_dup(&obj->progress_callback, &fcc);
30583054
if (zip_register_progress_callback_with_state(intern, rate, php_zip_progress_callback, php_zip_progress_callback_free, obj)) {
30593055
RETURN_FALSE;
30603056
}
3057+
zend_fcc_dup(&obj->progress_callback, &fcc);
30613058

30623059
RETURN_TRUE;
30633060
}
@@ -3108,14 +3105,11 @@ PHP_METHOD(ZipArchive, registerCancelCallback)
31083105
RETURN_THROWS();
31093106
}
31103107

3111-
/* free if called twice */
3112-
php_zip_cancel_callback_free(obj);
3113-
31143108
/* register */
3115-
zend_fcc_dup(&obj->cancel_callback, &fcc);
31163109
if (zip_register_cancel_callback_with_state(intern, php_zip_cancel_callback, php_zip_cancel_callback_free, obj)) {
31173110
RETURN_FALSE;
31183111
}
3112+
zend_fcc_dup(&obj->cancel_callback, &fcc);
31193113

31203114
RETURN_TRUE;
31213115
}

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)