Skip to content
Open
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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ PHP NEWS
. Support reference values in Phar::mungServer(). (ndossche)
. Invalid values now throw in Phar::mungServer() instead of being silently
ignored. (ndossche)
. Fixed a bypass of the magic ".phar" directory protection in
Phar::addEmptyDir() for paths starting with "/.phar". (Weilin Du)
. Phar::addEmptyDir() now allows non-magic directory names that merely
share the ".phar" prefix. (Weilin Du)
. Support overridden methods in SplFileInfo for getMTime() and getPathname()
when building a phar. (ndossche)
. Mark Phar::buildFromIterator() base directory argument as a path.
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ PHP 8.6 UPGRADE NOTES
- Phar:
. Phar::mungServer() now raises a ValueError when an invalid
argument value is passed instead of being silently ignored.
. Phar::addEmptyDir() now rejects `/.phar` paths in addition to `.phar`
paths, and raises the same BadMethodCallException for attempts to create
the reserved magic ".phar" directory through that form.
. Phar::addEmptyDir() now treats non-magic names that merely share the
`.phar` prefix as ordinary directories.

- PGSQL:
. pg_fetch_object() now reports the ValueError for a non-empty
Expand Down
13 changes: 10 additions & 3 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3789,9 +3789,16 @@ PHP_METHOD(Phar, addEmptyDir)

PHAR_ARCHIVE_OBJECT();

if (zend_string_starts_with_literal(dir_name, ".phar")) {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory");
RETURN_THROWS();
if (
zend_string_starts_with_literal(dir_name, ".phar")
|| zend_string_starts_with_literal(dir_name, "/.phar")
) {
size_t prefix_len = (ZSTR_VAL(dir_name)[0] == '/') + sizeof(".phar") - 1;
char next_char = ZSTR_VAL(dir_name)[prefix_len];
if (next_char == '/' || next_char == '\\' || next_char == '\0') {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory");
RETURN_THROWS();
}
}

phar_mkdir(&phar_obj->archive, dir_name);
Expand Down
9 changes: 9 additions & 0 deletions ext/phar/tests/mkdir.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ $a->addEmptyDir('.phar');
} catch (Exception $e) {
echo $e->getMessage(),"\n";
}
try {
$a->addEmptyDir('/.phar');
} catch (Exception $e) {
echo $e->getMessage(),"\n";
}
$a->addEmptyDir('/.pharx');
var_dump(is_dir($pname . '/.pharx'));
?>
--CLEAN--
<?php
Expand All @@ -43,3 +50,5 @@ Warning: rmdir(): phar error: cannot remove directory "" in phar "foo.phar", dir

Warning: rmdir(): phar error: cannot remove directory "a" in phar "%smkdir.phar.php", phar error: path "a" exists and is a not a directory in %smkdir.php on line %d
Cannot create a directory in magic ".phar" directory
Cannot create a directory in magic ".phar" directory
bool(true)
Loading