Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-17518: offset overflow phar extractTo() #17519

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,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;
Expand Down
23 changes: 23 additions & 0 deletions ext/phar/tests/gh17518.phpt
Original file line number Diff line number Diff line change
@@ -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"
Loading