summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2017-07-26 10:47:02 +0100
committerJoe Watkins <krakjoe@php.net>2017-07-26 10:47:22 +0100
commitbb9ea4e88b14ab9ae51370c6265d8a88c8532937 (patch)
treec71bd4fb650d408ea0364859ebe74025392d8ae6
parent747f5b23ae226c2c700d68f05178ff1085939dfa (diff)
parent6b1fbafdf0590ec293968d38c78641283b119848 (diff)
downloadphp-git-bb9ea4e88b14ab9ae51370c6265d8a88c8532937.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fix bug #74991 - include_path has a 4096 char (minus "__DIR__:") limit, in some PHAR cases
-rw-r--r--NEWS4
-rw-r--r--ext/phar/tests/bug74991.phpt23
-rw-r--r--ext/phar/util.c2
3 files changed, 28 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 1b91bb6565..07d466981f 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,10 @@ PHP NEWS
- Opcache:
. Fixed bug #74980 (Narrowing occurred during type inference). (Laruence)
+- phar:
+ . Fixed bug #74991 (include_path has a 4096 char limit in some cases).
+ (bwbroersma)
+
- Session:
. Fixed bug #74892 (Url Rewriting (trans_sid) not working on urls that start
with "#"). (Andrew Nester)
diff --git a/ext/phar/tests/bug74991.phpt b/ext/phar/tests/bug74991.phpt
new file mode 100644
index 0000000000..88d47be5ab
--- /dev/null
+++ b/ext/phar/tests/bug74991.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Phar: PHP bug #74991: include_path has a 4096 char (minus "__DIR__:") limit, in some PHAR cases
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+// create a sample file in a custom include_path to lookup from the phar later:
+mkdir('path');
+touch('path/needle.php');
+$p = new Phar('sample.phar');
+// the use of a sub path is crucial, and make the include_path 1 byte larger (=OVERFLOW) than the MAXPATHLEN, the include_path will then be truncated to 4096 (MAXPATHLEN) into 'phar://..sample.phar/some:xx..xx:pat' so it will fail to find needle.php:
+$p['some/file'] = "<?php const MAXPATHLEN = 4096, OVERFLOW = 1, PATH = 'path'; set_include_path(str_repeat('x', MAXPATHLEN - strlen(__DIR__ . PATH_SEPARATOR . PATH_SEPARATOR . PATH) + OVERFLOW) . PATH_SEPARATOR . PATH); require('needle.php');";
+$p->setStub("<?php Phar::mapPhar('sample.phar'); __HALT_COMPILER();");
+// execute the phar code:
+require('phar://sample.phar/some/file');
+--CLEAN--
+<?php
+unlink('path/needle.php');
+unlink('sample.phar');
+rmdir('path');
+--EXPECT--
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 803543d391..64a659d54d 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -309,7 +309,7 @@ splitted:
efree(test);
}
- spprintf(&path, MAXPATHLEN, "phar://%s/%s%c%s", arch, PHAR_G(cwd), DEFAULT_DIR_SEPARATOR, PG(include_path));
+ spprintf(&path, MAXPATHLEN + 1 + strlen(PG(include_path)), "phar://%s/%s%c%s", arch, PHAR_G(cwd), DEFAULT_DIR_SEPARATOR, PG(include_path));
efree(arch);
ret = php_resolve_path(filename, filename_len, path);
efree(path);