Skip to content

Commit c34b452

Browse files
cmb69sgolemon
authored andcommitted
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 ef6fe39 commit c34b452

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
@@ -1635,7 +1635,7 @@ 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;
1638+
char *pos, test = '\0';
16391639
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16401640
const int window_size = 1024;
16411641
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1664,7 +1664,8 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
16641664
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)")
16651665
}
16661666

1667-
if (recursion_count) {
1667+
if (!test && recursion_count) {
1668+
test = '\1';
16681669
pos = buffer+tokenlen;
16691670
if (!memcmp(pos, gz_magic, 3)) {
16701671
char err = 0;
@@ -1724,6 +1725,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17241725
compression = PHAR_FILE_COMPRESSED_GZ;
17251726

17261727
/* now, start over */
1728+
test = '\0';
17271729
if (!--recursion_count) {
17281730
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\"");
17291731
break;
@@ -1765,6 +1767,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17651767
compression = PHAR_FILE_COMPRESSED_BZ2;
17661768

17671769
/* now, start over */
1770+
test = '\0';
17681771
if (!--recursion_count) {
17691772
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\"");
17701773
break;

0 commit comments

Comments
 (0)