Skip to content

Commit fb27990

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix phpGH-20882: phar buildFromIterator breaks with missing base directory
2 parents 265c0c6 + b18b11e commit fb27990

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

ext/phar/phar_object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,12 +1384,12 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
13841384
zval *value;
13851385
bool close_fp = true;
13861386
struct _phar_t *p_obj = (struct _phar_t*) puser;
1387-
size_t str_key_len, base_len = ZSTR_LEN(p_obj->base);
1387+
size_t str_key_len, base_len = p_obj->base ? ZSTR_LEN(p_obj->base) : 0;
13881388
phar_entry_data *data;
13891389
php_stream *fp;
13901390
size_t fname_len;
13911391
size_t contents_len;
1392-
char *fname = NULL, *error = NULL, *base = ZSTR_VAL(p_obj->base), *save = NULL, *temp = NULL;
1392+
char *fname = NULL, *error = NULL, *base = p_obj->base ? ZSTR_VAL(p_obj->base) : NULL, *save = NULL, *temp = NULL;
13931393
zend_string *opened;
13941394
char *str_key;
13951395
zend_class_entry *ce = p_obj->c;

ext/phar/tests/gh20882.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-20882 (phar buildFromIterator breaks with missing base directory)
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--FILE--
8+
<?php
9+
$phar = new \Phar(__DIR__ . "/test.phar");
10+
try {
11+
$phar->buildFromIterator(
12+
new RecursiveIteratorIterator(
13+
new RecursiveDirectoryIterator(__DIR__.'/test79082', FilesystemIterator::SKIP_DOTS)
14+
),
15+
null
16+
);
17+
} catch (BadMethodCallException $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
?>
21+
--EXPECT--
22+
Iterator RecursiveIteratorIterator returns an SplFileInfo object, so base directory must be specified

0 commit comments

Comments
 (0)