Skip to content

Commit 2c4f4e0

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
2 parents c997212 + 4e00b14 commit 2c4f4e0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ext/zip/php_zip.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,11 @@ PHP_METHOD(ZipArchive, setEncryptionName)
23382338
RETURN_FALSE;
23392339
}
23402340

2341+
if (UNEXPECTED(zip_file_set_encryption(intern, idx, ZIP_EM_NONE, NULL) < 0)) {
2342+
php_error_docref(NULL, E_WARNING, "password reset failed");
2343+
RETURN_FALSE;
2344+
}
2345+
23412346
if (zip_file_set_encryption(intern, idx, (zip_uint16_t)method, password)) {
23422347
RETURN_FALSE;
23432348
}
@@ -2361,6 +2366,11 @@ PHP_METHOD(ZipArchive, setEncryptionIndex)
23612366

23622367
ZIP_FROM_OBJECT(intern, self);
23632368

2369+
if (UNEXPECTED(zip_file_set_encryption(intern, index, ZIP_EM_NONE, NULL) < 0)) {
2370+
php_error_docref(NULL, E_WARNING, "password reset failed");
2371+
RETURN_FALSE;
2372+
}
2373+
23642374
if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
23652375
RETURN_FALSE;
23662376
}

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)