1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-20882: phar buildFromIterator breaks with missing base directory

Broke in f57526a07a because of changing a char*+size_t pair to
zend_string* (which can't handle NULL pointers in its macros).

Closes GH-20888.
This commit is contained in:
Niels Dossche
2026-01-09 22:03:07 +01:00
parent b5d6377ada
commit a6e0d8e359
3 changed files with 28 additions and 2 deletions

4
NEWS
View File

@@ -10,6 +10,10 @@ PHP NEWS
. Fixed bug GH-20833 (mb_str_pad() divide by zero if padding string is
invalid in the encoding). (ndossche)
- Phar:
. Fixed bug GH-20882 (buildFromIterator breaks with missing base directory).
(ndossche)
- Readline:
. Fixed bug GH-18139 (Memory leak when overriding some settings
via readline_info()). (ndossche)

View File

@@ -1397,12 +1397,12 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
zval *value;
bool close_fp = 1;
struct _phar_t *p_obj = (struct _phar_t*) puser;
size_t str_key_len, base_len = ZSTR_LEN(p_obj->base);
size_t str_key_len, base_len = p_obj->base ? ZSTR_LEN(p_obj->base) : 0;
phar_entry_data *data;
php_stream *fp;
size_t fname_len;
size_t contents_len;
char *fname, *error = NULL, *base = ZSTR_VAL(p_obj->base), *save = NULL, *temp = NULL;
char *fname, *error = NULL, *base = p_obj->base ? ZSTR_VAL(p_obj->base) : NULL, *save = NULL, *temp = NULL;
zend_string *opened;
char *str_key;
zend_class_entry *ce = p_obj->c;

View File

@@ -0,0 +1,22 @@
--TEST--
GH-20882 (phar buildFromIterator breaks with missing base directory)
--EXTENSIONS--
phar
--INI--
phar.readonly=0
--FILE--
<?php
$phar = new \Phar(__DIR__ . "/test.phar");
try {
$phar->buildFromIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(__DIR__.'/test79082', FilesystemIterator::SKIP_DOTS)
),
null
);
} catch (BadMethodCallException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Iterator RecursiveIteratorIterator returns an SplFileInfo object, so base directory must be specified