Skip to content

Commit 4e00b14

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 1bda46e + 3ee56f6 commit 4e00b14

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ PHP NEWS
4848

4949
- Zip:
5050
. Fixed bug GH-19688 (Remove pattern overflow in zip addGlob()). (nielsdos)
51+
. Fixed bug GH-19932 (Memory leak in zip setEncryptionName()/setEncryptionIndex()).
52+
(David Carlier)
5153

5254
25 Sep 2025, PHP 8.4.13
5355

ext/zip/php_zip.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,11 @@ PHP_METHOD(ZipArchive, setEncryptionName)
23862386
RETURN_FALSE;
23872387
}
23882388

2389+
if (UNEXPECTED(zip_file_set_encryption(intern, idx, ZIP_EM_NONE, NULL) < 0)) {
2390+
php_error_docref(NULL, E_WARNING, "password reset failed");
2391+
RETURN_FALSE;
2392+
}
2393+
23892394
if (zip_file_set_encryption(intern, idx, (zip_uint16_t)method, password)) {
23902395
RETURN_FALSE;
23912396
}
@@ -2409,6 +2414,11 @@ PHP_METHOD(ZipArchive, setEncryptionIndex)
24092414

24102415
ZIP_FROM_OBJECT(intern, self);
24112416

2417+
if (UNEXPECTED(zip_file_set_encryption(intern, index, ZIP_EM_NONE, NULL) < 0)) {
2418+
php_error_docref(NULL, E_WARNING, "password reset failed");
2419+
RETURN_FALSE;
2420+
}
2421+
24122422
if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
24132423
RETURN_FALSE;
24142424
}

ext/zip/tests/gh19932.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-19932 (ZipArchive::setEncryptionName()/setEncryptionIndex() memory leak)
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php if (!method_exists('ZipArchive', 'setEncryptionName')) die('skip encryption not supported'); ?>
7+
--FILE--
8+
<?php
9+
$zip = new ZipArchive();
10+
$zip->open(__DIR__ . "/gh19932.zip", ZipArchive::CREATE);
11+
$zip->addFromString("test.txt", "test");
12+
$zip->setEncryptionName("test.txt", ZipArchive::EM_AES_256, "password");
13+
$zip->setEncryptionName("test.txt", ZipArchive::EM_AES_256, "password");
14+
$zip->setEncryptionIndex("0", ZipArchive::EM_AES_256, "password");
15+
$zip->setEncryptionIndex("0", ZipArchive::EM_AES_256, "password");
16+
$zip->close();
17+
echo "OK";
18+
?>
19+
--CLEAN--
20+
<?php
21+
@unlink(__DIR__ . "/gh19932.zip");
22+
?>
23+
--EXPECT--
24+
OK
25+

0 commit comments

Comments
 (0)