Skip to content

Commit ef52e44

Browse files
committed
Fixed bug 64343
PharData::extractTo fails for tarball created by BSD tar Phar did not know about PAX style global/file headers. Skip them, to be able to read the contents of those archives.
1 parent a04ab4b commit ef52e44

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ PHP NEWS
4747
(Daniel Lowrey)
4848
. Add a check for RAND_egd to allow compiling against LibreSSL (Leigh)
4949

50+
- Phar:
51+
. Fixed bug 64343 (PharData::extractTo fails for tarball created by BSD tar).
52+
(Mike)
53+
5054
- Postgres:
5155
. Fixed bug #68741 (Null pointer dereference) (CVE-2015-1352). (Laruence)
5256

ext/phar/phar_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
#define TAR_SYMLINK '2'
125125
#define TAR_DIR '5'
126126
#define TAR_NEW '8'
127+
#define TAR_GLOBAL_HDR 'g'
128+
#define TAR_FILE_HDR 'x'
127129

128130
#define PHAR_MUNG_PHP_SELF (1<<0)
129131
#define PHAR_MUNG_REQUEST_URI (1<<1)

ext/phar/tar.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias,
255255
size = entry.uncompressed_filesize = entry.compressed_filesize =
256256
phar_tar_number(hdr->size, sizeof(hdr->size));
257257

258+
/* skip global/file headers (pax) */
259+
if (!old && (hdr->typeflag == TAR_GLOBAL_HDR || hdr->typeflag == TAR_FILE_HDR)) {
260+
size = (size+511)&~511;
261+
goto next;
262+
}
263+
258264
if (((!old && hdr->prefix[0] == 0) || old) && strlen(hdr->name) == sizeof(".phar/signature.bin")-1 && !strncmp(hdr->name, ".phar/signature.bin", sizeof(".phar/signature.bin")-1)) {
259265
off_t curloc;
260266

@@ -548,6 +554,7 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias,
548554
size = (size+511)&~511;
549555

550556
if (((hdr->typeflag == '\0') || (hdr->typeflag == TAR_FILE)) && size > 0) {
557+
next:
551558
/* this is not good enough - seek succeeds even on truncated tars */
552559
php_stream_seek(fp, size, SEEK_CUR);
553560
if ((uint)php_stream_tell(fp) > totalsize) {

ext/phar/tests/tar/bug64343.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #64343 (phar cannot open tars with pax headers)
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
8+
echo "Test\n";
9+
10+
$phar = new PharData(__DIR__."/files/bug64343.tar");
11+
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
Test
16+
===DONE===

ext/phar/tests/tar/files/bug64343.tar

10 KB
Binary file not shown.

0 commit comments

Comments
 (0)