Skip to content

Commit 432bf19

Browse files
committed
Fix regression introduced by fixing bug 81726
When a tar phar is created, `phar_open_from_fp()` is also called, but since the file has just been created, none of the format checks can succeed, so we continue to loop, but must not check again for the format. Therefore, we bring back the old `test` variable. Closes GH-9620.
1 parent 6f586ef commit 432bf19

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/phar/phar.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
15841584
const char zip_magic[] = "PK\x03\x04";
15851585
const char gz_magic[] = "\x1f\x8b\x08";
15861586
const char bz_magic[] = "BZh";
1587-
char *pos;
1587+
char *pos, test = '\0';
15881588
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
15891589
const int window_size = 1024;
15901590
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1613,7 +1613,8 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16131613
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16141614
}
16151615

1616-
if (recursion_count) {
1616+
if (!test && recursion_count) {
1617+
test = '\1';
16171618
pos = buffer+tokenlen;
16181619
if (!memcmp(pos, gz_magic, 3)) {
16191620
char err = 0;
@@ -1673,6 +1674,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16731674
compression = PHAR_FILE_COMPRESSED_GZ;
16741675

16751676
/* now, start over */
1677+
test = '\0';
16761678
if (!--recursion_count) {
16771679
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\"");
16781680
break;
@@ -1714,6 +1716,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17141716
compression = PHAR_FILE_COMPRESSED_BZ2;
17151717

17161718
/* now, start over */
1719+
test = '\0';
17171720
if (!--recursion_count) {
17181721
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\"");
17191722
break;

0 commit comments

Comments
 (0)