]> granicus.if.org Git - php/commitdiff
fix bug #67761
authorMichael Wallner <mike@php.net>
Mon, 30 Mar 2015 12:41:30 +0000 (14:41 +0200)
committerMichael Wallner <mike@php.net>
Mon, 30 Mar 2015 12:41:30 +0000 (14:41 +0200)
Phar::mapPhar fails for Phars inside a path containing ".tar".

Strengthen the silly .tar file extension check.

NEWS
ext/phar/tar.c
ext/phar/tests/tar/bug67761.phpt [new file with mode: 0644]
ext/phar/tests/tar/files/bug67761.tar/bug67761.phar [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1cbaff8f023f8a8c83b0c39a4aaa86a57060b1a2..f073c9cf040f82a596320e64d046ab032b3cbd70 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,8 +40,10 @@ PHP                                                                        NEWS
   . Add a check for RAND_egd to allow compiling against LibreSSL (Leigh)
 
 - Phar:
-  . Fixed bug 64343 (PharData::extractTo fails for tarball created by BSD tar).
+  . Fixed bug #64343 (PharData::extractTo fails for tarball created by BSD tar).
     (Mike)
+  . Fixed bug #67761 (Phar::mapPhar fails for Phars inside a path containing 
+    ".tar"). (Mike)
 
 - Postgres:
   . Fixed bug #68741 (Null pointer dereference) (CVE-2015-1352). (Laruence)
index 844c6b54198821edc76b6b188824ffcf06994d7c..c4a81fb799b534a3e14e6a61c22a303ca73cd414 100644 (file)
@@ -102,7 +102,7 @@ int phar_is_tar(char *buf, char *fname) /* {{{ */
        tar_header *header = (tar_header *) buf;
        php_uint32 checksum = phar_tar_number(header->checksum, sizeof(header->checksum));
        php_uint32 ret;
-       char save[sizeof(header->checksum)];
+       char save[sizeof(header->checksum)], *bname;
 
        /* assume that the first filename in a tar won't begin with <?php */
        if (!strncmp(buf, "<?php", sizeof("<?php")-1)) {
@@ -113,7 +113,10 @@ int phar_is_tar(char *buf, char *fname) /* {{{ */
        memset(header->checksum, ' ', sizeof(header->checksum));
        ret = (checksum == phar_tar_checksum(buf, 512));
        memcpy(header->checksum, save, sizeof(header->checksum));
-       if (!ret && strstr(fname, ".tar")) {
+       if ((bname = strrchr(fname, PHP_DIR_SEPARATOR))) {
+               fname = bname;
+       }
+       if (!ret && (bname = strstr(fname, ".tar")) && (bname[4] == '\0' || bname[4] == '.')) {
                /* probably a corrupted tar - so we will pretend it is one */
                return 1;
        }
diff --git a/ext/phar/tests/tar/bug67761.phpt b/ext/phar/tests/tar/bug67761.phpt
new file mode 100644 (file)
index 0000000..860213d
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #67761 (Phar::mapPhar fails for Phars inside a path containing ".tar")
+--SKIPIF--
+<?php extension_loaded("phar") or die("SKIP need ext/phar suppport"); ?>
+--FILE--
+<?php 
+
+echo "Test\n";
+
+include __DIR__."/files/bug67761.tar/bug67761.phar";
+
+?>
+
+===DONE===
+--EXPECT--
+Test
+#!/usr/bin/env php
+Test
+===DONE===
diff --git a/ext/phar/tests/tar/files/bug67761.tar/bug67761.phar b/ext/phar/tests/tar/files/bug67761.tar/bug67761.phar
new file mode 100644 (file)
index 0000000..408eca1
Binary files /dev/null and b/ext/phar/tests/tar/files/bug67761.tar/bug67761.phar differ