Skip to content

Commit 01677ca

Browse files
committed
Merge branch 'PHP-8.2'
2 parents ed78175 + 25290cd commit 01677ca

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
@@ -1626,7 +1626,8 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16261626
const char zip_magic[] = "PK\x03\x04";
16271627
const char gz_magic[] = "\x1f\x8b\x08";
16281628
const char bz_magic[] = "BZh";
1629-
char *pos, test = '\0';
1629+
char *pos;
1630+
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16301631
const int window_size = 1024;
16311632
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
16321633
const zend_long readsize = sizeof(buffer) - sizeof(token);
@@ -1654,8 +1655,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16541655
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16551656
}
16561657

1657-
if (!test) {
1658-
test = '\1';
1658+
if (recursion_count) {
16591659
pos = buffer+tokenlen;
16601660
if (!memcmp(pos, gz_magic, 3)) {
16611661
char err = 0;
@@ -1715,7 +1715,10 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17151715
compression = PHAR_FILE_COMPRESSED_GZ;
17161716

17171717
/* now, start over */
1718-
test = '\0';
1718+
if (!--recursion_count) {
1719+
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\"");
1720+
break;
1721+
}
17191722
continue;
17201723
} else if (!memcmp(pos, bz_magic, 3)) {
17211724
php_stream_filter *filter;
@@ -1753,7 +1756,10 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17531756
compression = PHAR_FILE_COMPRESSED_BZ2;
17541757

17551758
/* now, start over */
1756-
test = '\0';
1759+
if (!--recursion_count) {
1760+
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\"");
1761+
break;
1762+
}
17571763
continue;
17581764
}
17591765

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
@@ -137,6 +137,20 @@ PHPAPI void php_register_variable_ex(const char *var_name, zval *val, zval *trac
137137
}
138138
var_len = p - var;
139139

140+
/* Discard variable if mangling made it start with __Host-, where pre-mangling it did not start with __Host- */
141+
if (strncmp(var, "__Host-", sizeof("__Host-")-1) == 0 && strncmp(var_name, "__Host-", sizeof("__Host-")-1) != 0) {
142+
zval_ptr_dtor_nogc(val);
143+
free_alloca(var_orig, use_heap);
144+
return;
145+
}
146+
147+
/* Discard variable if mangling made it start with __Secure-, where pre-mangling it did not start with __Secure- */
148+
if (strncmp(var, "__Secure-", sizeof("__Secure-")-1) == 0 && strncmp(var_name, "__Secure-", sizeof("__Secure-")-1) != 0) {
149+
zval_ptr_dtor_nogc(val);
150+
free_alloca(var_orig, use_heap);
151+
return;
152+
}
153+
140154
if (var_len==0) { /* empty variable name, or variable name with a space in it */
141155
zval_ptr_dtor_nogc(val);
142156
free_alloca(var_orig, use_heap);

0 commit comments

Comments
 (0)