Skip to content

Commit 98aba6c

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-19688: Remove pattern overflow in zip addGlob()
2 parents a76d01d + 901f71e commit 98aba6c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ PHP NEWS
1010
. Fixed bug GH-12265 (Cloning an object breaks serialization recursion).
1111
(nielsdos)
1212

13+
- Zip:
14+
. Fixed bug GH-19688 (Remove pattern overflow in zip addGlob()). (nielsdos)
15+
1316
25 Sep 2025, PHP 8.4.13
1417

1518
- Core:

ext/zip/php_zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17901790
basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
17911791
file_stripped = ZSTR_VAL(basename);
17921792
file_stripped_len = ZSTR_LEN(basename);
1793-
} else if (opts.remove_path && !memcmp(Z_STRVAL_P(zval_file), opts.remove_path, opts.remove_path_len)) {
1793+
} else if (opts.remove_path && Z_STRLEN_P(zval_file) > opts.remove_path_len && !memcmp(Z_STRVAL_P(zval_file), opts.remove_path, opts.remove_path_len)) {
17941794
if (IS_SLASH(Z_STRVAL_P(zval_file)[opts.remove_path_len])) {
17951795
file_stripped = Z_STRVAL_P(zval_file) + opts.remove_path_len + 1;
17961796
file_stripped_len = Z_STRLEN_P(zval_file) - opts.remove_path_len - 1;

ext/zip/tests/gh19688.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-19688 (Remove pattern overflow in zip addGlob())
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
$dir = __DIR__ . '/';
8+
$testfile = $dir . '001.phpt';
9+
$zip = new ZipArchive();
10+
$filename = $dir . '/gh19688.zip';
11+
$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
12+
$options = array('remove_path' => $dir . 'a very long string here that will overrun');
13+
$zip->addGlob($testfile, 0, $options);
14+
var_dump($zip->getNameIndex(0));
15+
?>
16+
--CLEAN--
17+
<?php
18+
@unlink(__DIR__ . '/gh19688.zip');
19+
?>
20+
--EXPECTF--
21+
string(%d) "%s001.phpt"

0 commit comments

Comments
 (0)