Skip to content

Commit ec4939b

Browse files
nielsdosGirgias
authored andcommitted
Fix incorrect check in phar tar parsing
The entry.flags was used to check whether the entry has the directory flag. The flags however were masked to only contain the permissions. We need to check the mode, before the permission masking, instead of the flags to check whether it is a directory. Closes GH-10464 Signed-off-by: George Peter Banyard <girgias@php.net>
1 parent 284c293 commit ec4939b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PHP NEWS
1717
- Opcache:
1818
. Fix incorrect page_size check. (nielsdos)
1919

20+
- Phar:
21+
. Fix incorrect check in phar tar parsing. (nielsdos)
22+
2023
- Standard:
2124
. Fixed bug GH-10292 (Made the default value of the first param of srand() and
2225
mt_srand() unknown). (kocsismate)

ext/phar/tar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,15 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia
478478
return FAILURE;
479479
}
480480

481+
uint32_t entry_mode = phar_tar_number(hdr->mode, sizeof(hdr->mode));
481482
entry.tar_type = ((old & (hdr->typeflag == '\0')) ? TAR_FILE : hdr->typeflag);
482483
entry.offset = entry.offset_abs = pos; /* header_offset unused in tar */
483484
entry.fp_type = PHAR_FP;
484-
entry.flags = phar_tar_number(hdr->mode, sizeof(hdr->mode)) & PHAR_ENT_PERM_MASK;
485+
entry.flags = entry_mode & PHAR_ENT_PERM_MASK;
485486
entry.timestamp = phar_tar_number(hdr->mtime, sizeof(hdr->mtime));
486487
entry.is_persistent = myphar->is_persistent;
487488

488-
if (old && entry.tar_type == TAR_FILE && S_ISDIR(entry.flags)) {
489+
if (old && entry.tar_type == TAR_FILE && S_ISDIR(entry_mode)) {
489490
entry.tar_type = TAR_DIR;
490491
}
491492

0 commit comments

Comments
 (0)