Skip to content

Commit 0a6326c

Browse files
committed
Fix uouv when handling empty options in ZipArchive::addGlob()
Reported by OpenAI AARDVARK. php_zip_parse_option is only called when options are passed to the function. Prior to this patch, php_zip_parse_option was responsible for zeroing the opts variable. So in the case when php_zip_parse_option is not called, opts remains uninitialized yet it is being used anyway. By just always zeroing opts at declaration time, we avoid this issue and we are unlikely to reintroduce this in the future. Closes GH-18329.
1 parent 9d4f8b5 commit 0a6326c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Diff for: NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ PHP NEWS
4343
leads to negative stream position). (David Carlier)
4444
. Fix resource leak in iptcembed() on error. (nielsdos)
4545

46+
- Zip:
47+
. Fix uouv when handling empty options in ZipArchive::addGlob(). (nielsdos)
48+
4649
10 Apr 2025, PHP 8.3.20
4750

4851
- Core:

Diff for: ext/zip/php_zip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,13 @@ typedef struct {
354354
#endif
355355
} zip_options;
356356

357+
/* Expects opts to be zero-initialized. */
357358
static int php_zip_parse_options(HashTable *options, zip_options *opts)
358359
/* {{{ */
359360
{
360361
zval *option;
361362

362363
/* default values */
363-
memset(opts, 0, sizeof(zip_options));
364364
opts->flags = ZIP_FL_OVERWRITE;
365365
opts->comp_method = -1; /* -1 to not change default */
366366
#ifdef HAVE_ENCRYPTION
@@ -1732,7 +1732,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17321732
size_t path_len = 1;
17331733
zend_long glob_flags = 0;
17341734
HashTable *options = NULL;
1735-
zip_options opts;
1735+
zip_options opts = {0};
17361736
int found;
17371737
zend_string *pattern;
17381738

Diff for: ext/zip/tests/addGlob_empty_options.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
addGlob with empty options
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
8+
touch($file = __DIR__ . '/addglob_empty_options.zip');
9+
10+
$zip = new ZipArchive();
11+
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
12+
$zip->addGlob(__FILE__, 0, []);
13+
var_dump($zip->statIndex(0)['name'] === __FILE__);
14+
$zip->close();
15+
16+
?>
17+
--CLEAN--
18+
<?php
19+
@unlink(__DIR__ . '/addglob_empty_options.zip');
20+
?>
21+
--EXPECT--
22+
bool(true)

0 commit comments

Comments
 (0)