Skip to content

Commit 7cc8719

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17518: offset overflow phar extractTo()
2 parents 22704af + eab209d commit 7cc8719

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ PHP NEWS
6262
the cpu mask argument with entries type different than int/string.
6363
(David Carlier)
6464

65+
- Phar:
66+
. Fixed bug GH-17518 (offset overflow phar extractTo()). (nielsdos)
67+
6568
- PHPDBG:
6669
. Fix crashes in function registration + test. (nielsdos, Girgias)
6770

ext/phar/phar_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4333,7 +4333,7 @@ static int extract_helper(phar_archive_data *archive, zend_string *search, char
43334333
if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1;
43344334
extracted++;
43354335
} ZEND_HASH_FOREACH_END();
4336-
} else if ('/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) {
4336+
} else if (ZSTR_LEN(search) > 0 && '/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) {
43374337
/* ends in "/" -- extract all entries having that prefix */
43384338
ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) {
43394339
if (0 != strncmp(ZSTR_VAL(search), entry->filename, ZSTR_LEN(search))) continue;

ext/phar/tests/gh17518.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-17518 (offset overflow phar extractTo())
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--FILE--
8+
<?php
9+
$fname = __DIR__.'/gh17518.phar.php';
10+
$phar = new Phar($fname);
11+
$phar['a'] = 'b';
12+
try {
13+
$phar->extractTo(__DIR__ . '/gh17518', '');
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), "\n";
16+
}
17+
?>
18+
--CLEAN--
19+
<?php
20+
@unlink(__DIR__.'/gh17518.phar.php');
21+
?>
22+
--EXPECTF--
23+
PharException: phar error: attempted to extract non-existent file or directory "" from phar "%sgh17518.phar.php"

0 commit comments

Comments
 (0)