Skip to content

Commit 092fd61

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
2 parents 4c8dabf + 3064540 commit 092fd61

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ PHP NEWS
1111
LXB_API as __declspec(dllimport) when linked statically into PHP.
1212
(Luther Monson)
1313

14+
- Phar:
15+
. Fixed a bypass of the magic ".phar" directory protection in
16+
Phar::addEmptyDir() for paths starting with "/.phar", while allowing
17+
non-magic directory names that merely share the ".phar" prefix. (Weilin Du)
18+
1419
- Zlib:
1520
. Fixed memory leak if deflate initialization fails and there is a dict.
1621
(ndossche)

ext/phar/phar_object.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,9 +3862,16 @@ PHP_METHOD(Phar, addEmptyDir)
38623862

38633863
PHAR_ARCHIVE_OBJECT();
38643864

3865-
if (zend_string_starts_with_literal(dir_name, ".phar")) {
3866-
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory");
3867-
RETURN_THROWS();
3865+
if (
3866+
zend_string_starts_with_literal(dir_name, ".phar")
3867+
|| zend_string_starts_with_literal(dir_name, "/.phar")
3868+
) {
3869+
size_t prefix_len = (ZSTR_VAL(dir_name)[0] == '/') + sizeof(".phar")-1;
3870+
char next_char = ZSTR_VAL(dir_name)[prefix_len];
3871+
if (next_char == '/' || next_char == '\\' || next_char == '\0') {
3872+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory");
3873+
RETURN_THROWS();
3874+
}
38683875
}
38693876

38703877
phar_mkdir(&phar_obj->archive, dir_name);

ext/phar/tests/mkdir.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ $a->addEmptyDir('.phar');
2424
} catch (Exception $e) {
2525
echo $e->getMessage(),"\n";
2626
}
27+
try {
28+
$a->addEmptyDir('/.phar');
29+
} catch (Exception $e) {
30+
echo $e->getMessage(),"\n";
31+
}
32+
$a->addEmptyDir('/.pharx');
33+
var_dump(is_dir($pname . '/.pharx'));
2734
?>
2835
--CLEAN--
2936
<?php
@@ -43,3 +50,5 @@ Warning: rmdir(): phar error: cannot remove directory "" in phar "foo.phar", dir
4350

4451
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
4552
Cannot create a directory in magic ".phar" directory
53+
Cannot create a directory in magic ".phar" directory
54+
bool(true)

0 commit comments

Comments
 (0)