Skip to content

Commit def8c8d

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
2 parents 12afd0c + 6f586ef commit def8c8d

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

ext/phar/phar.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,8 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16351635
const char zip_magic[] = "PK\x03\x04";
16361636
const char gz_magic[] = "\x1f\x8b\x08";
16371637
const char bz_magic[] = "BZh";
1638-
char *pos, test = '\0';
1638+
char *pos;
1639+
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16391640
const int window_size = 1024;
16401641
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
16411642
const zend_long readsize = sizeof(buffer) - sizeof(token);
@@ -1663,8 +1664,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16631664
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16641665
}
16651666

1666-
if (!test) {
1667-
test = '\1';
1667+
if (recursion_count) {
16681668
pos = buffer+tokenlen;
16691669
if (!memcmp(pos, gz_magic, 3)) {
16701670
char err = 0;
@@ -1724,7 +1724,10 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17241724
compression = PHAR_FILE_COMPRESSED_GZ;
17251725

17261726
/* now, start over */
1727-
test = '\0';
1727+
if (!--recursion_count) {
1728+
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\"");
1729+
break;
1730+
}
17281731
continue;
17291732
} else if (!memcmp(pos, bz_magic, 3)) {
17301733
php_stream_filter *filter;
@@ -1762,7 +1765,10 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17621765
compression = PHAR_FILE_COMPRESSED_BZ2;
17631766

17641767
/* now, start over */
1765-
test = '\0';
1768+
if (!--recursion_count) {
1769+
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\"");
1770+
break;
1771+
}
17661772
continue;
17671773
}
17681774

ext/phar/tests/bug81726.gz

204 Bytes
Binary file not shown.

ext/phar/tests/bug81726.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #81726 (phar wrapper: DOS when using quine gzip file)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("phar")) die("skip phar extension not available");
6+
if (!extension_loaded("zlib")) die("skip zlib extension not available");
7+
?>
8+
--FILE--
9+
<?php
10+
var_dump(fopen("phar://" . __DIR__ . "/bug81726.gz", "r"));
11+
?>
12+
--EXPECTF--
13+
Warning: fopen(phar://%s): failed to open stream: unable to decompress gzipped phar archive "%s" in %s on line %d
14+
bool(false)

ext/standard/tests/bug81727.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #81727: $_COOKIE name starting with ..Host/..Secure should be discarded
3+
--COOKIE--
4+
..Host-test=ignore; __Host-test=correct; . Secure-test=ignore; . Elephpant=Awesome;
5+
--FILE--
6+
<?php
7+
var_dump($_COOKIE);
8+
?>
9+
--EXPECT--
10+
array(2) {
11+
["__Host-test"]=>
12+
string(7) "correct"
13+
["__Elephpant"]=>
14+
string(7) "Awesome"
15+
}

main/php_variables.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
104104
}
105105
var_len = p - var;
106106

107+
/* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
108+
if (strncmp(var, "__Host-", sizeof("__Host-")-1) == 0 && strncmp(var_name, "__Host-", sizeof("__Host-")-1) != 0) {
109+
zval_ptr_dtor_nogc(val);
110+
free_alloca(var_orig, use_heap);
111+
return;
112+
}
113+
114+
/* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
115+
if (strncmp(var, "__Secure-", sizeof("__Secure-")-1) == 0 && strncmp(var_name, "__Secure-", sizeof("__Secure-")-1) != 0) {
116+
zval_ptr_dtor_nogc(val);
117+
free_alloca(var_orig, use_heap);
118+
return;
119+
}
120+
107121
if (var_len==0) { /* empty variable name, or variable name with a space in it */
108122
zval_ptr_dtor_nogc(val);
109123
free_alloca(var_orig, use_heap);

0 commit comments

Comments
 (0)