Skip to content

Commit a6e0d8e

Browse files
committed
Fix GH-20882: phar buildFromIterator breaks with missing base directory
Broke in f57526a because of changing a char*+size_t pair to zend_string* (which can't handle NULL pointers in its macros). Closes GH-20888.
1 parent b5d6377 commit a6e0d8e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug GH-20833 (mb_str_pad() divide by zero if padding string is
1111
invalid in the encoding). (ndossche)
1212

13+
- Phar:
14+
. Fixed bug GH-20882 (buildFromIterator breaks with missing base directory).
15+
(ndossche)
16+
1317
- Readline:
1418
. Fixed bug GH-18139 (Memory leak when overriding some settings
1519
via readline_info()). (ndossche)

ext/phar/phar_object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,12 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
13971397
zval *value;
13981398
bool close_fp = 1;
13991399
struct _phar_t *p_obj = (struct _phar_t*) puser;
1400-
size_t str_key_len, base_len = ZSTR_LEN(p_obj->base);
1400+
size_t str_key_len, base_len = p_obj->base ? ZSTR_LEN(p_obj->base) : 0;
14011401
phar_entry_data *data;
14021402
php_stream *fp;
14031403
size_t fname_len;
14041404
size_t contents_len;
1405-
char *fname, *error = NULL, *base = ZSTR_VAL(p_obj->base), *save = NULL, *temp = NULL;
1405+
char *fname, *error = NULL, *base = p_obj->base ? ZSTR_VAL(p_obj->base) : NULL, *save = NULL, *temp = NULL;
14061406
zend_string *opened;
14071407
char *str_key;
14081408
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)