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

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-17518: offset overflow phar extractTo()
This commit is contained in:
Niels Dossche
2025-01-19 13:05:55 +01:00
3 changed files with 27 additions and 1 deletions

3
NEWS
View File

@@ -62,6 +62,9 @@ PHP NEWS
the cpu mask argument with entries type different than int/string.
(David Carlier)
- Phar:
. Fixed bug GH-17518 (offset overflow phar extractTo()). (nielsdos)
- PHPDBG:
. Fix crashes in function registration + test. (nielsdos, Girgias)

View File

@@ -4333,7 +4333,7 @@ static int extract_helper(phar_archive_data *archive, zend_string *search, char
if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1;
extracted++;
} ZEND_HASH_FOREACH_END();
} else if ('/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) {
} else if (ZSTR_LEN(search) > 0 && '/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) {
/* ends in "/" -- extract all entries having that prefix */
ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) {
if (0 != strncmp(ZSTR_VAL(search), entry->filename, ZSTR_LEN(search))) continue;

View File

@@ -0,0 +1,23 @@
--TEST--
GH-17518 (offset overflow phar extractTo())
--EXTENSIONS--
phar
--INI--
phar.readonly=0
--FILE--
<?php
$fname = __DIR__.'/gh17518.phar.php';
$phar = new Phar($fname);
$phar['a'] = 'b';
try {
$phar->extractTo(__DIR__ . '/gh17518', '');
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}
?>
--CLEAN--
<?php
@unlink(__DIR__.'/gh17518.phar.php');
?>
--EXPECTF--
PharException: phar error: attempted to extract non-existent file or directory "" from phar "%sgh17518.phar.php"