From ddc051cebe56e343ca28599d6e9c989d597658dc Mon Sep 17 00:00:00 2001 From: Steph Fox Date: Fri, 25 Jan 2008 17:26:18 +0000 Subject: [PATCH] - Rewrite stub to take up slightly less space - Fix tests - Test phars should probably be regenerated, although only one fails here currently (nophar.phar in web context) --- ext/phar/makestub.php | 4 +- ext/phar/shortarc.php | 211 ++++++++++----------- ext/phar/stub.h | 13 +- ext/phar/tests/031.phpt | 2 +- ext/phar/tests/phar_commitwrite.phpt | 42 ++-- ext/phar/tests/phar_create_in_cwd.phpt | 2 +- ext/phar/tests/phar_createdefaultstub.phpt | 130 ++++++------- 7 files changed, 190 insertions(+), 214 deletions(-) diff --git a/ext/phar/makestub.php b/ext/phar/makestub.php index 3483874acc..e972c935dc 100644 --- a/ext/phar/makestub.php +++ b/ext/phar/makestub.php @@ -93,9 +93,7 @@ foreach ($s3split as $i => $chunk) { $stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '"; '; } -$stub .= " - -\tstatic const int newstub_len = " . $slen . "; +$stub .= "\n\tstatic const int newstub_len = " . $slen . "; \t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d' . str_repeat('%s', $s3count) . '", newstub0, web'; diff --git a/ext/phar/shortarc.php b/ext/phar/shortarc.php index 4e926553c7..325d74df55 100644 --- a/ext/phar/shortarc.php +++ b/ext/phar/shortarc.php @@ -1,98 +1,100 @@ 2, - 'c' => 'text/plain', - 'cc' => 'text/plain', - 'cpp' => 'text/plain', - 'c++' => 'text/plain', - 'dtd' => 'text/plain', - 'h' => 'text/plain', - 'log' => 'text/plain', - 'rng' => 'text/plain', - 'txt' => 'text/plain', - 'xsd' => 'text/plain', - 'php' => 1, - 'inc' => 1, - 'avi' => 'video/avi', - 'bmp' => 'image/bmp', - 'css' => 'text/css', - 'gif' => 'image/gif', - 'htm' => 'text/html', - 'html' => 'text/html', - 'htmls' => 'text/html', - 'ico' => 'image/x-ico', - 'jpe' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'js' => 'application/x-javascript', - 'midi' => 'audio/midi', - 'mid' => 'audio/midi', - 'mod' => 'audio/mod', - 'mov' => 'movie/quicktime', - 'mp3' => 'audio/mp3', - 'mpg' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'pdf' => 'application/pdf', - 'png' => 'image/png', - 'swf' => 'application/shockwave-flash', - 'tif' => 'image/tiff', - 'tiff' => 'image/tiff', - 'wav' => 'audio/wav', - 'xbm' => 'image/xbm', - 'xml' => 'text/xml', - ); - $basename = basename(__FILE__); - if (!strpos($_SERVER['REQUEST_URI'], $basename)) { - chdir(Extract_Phar::$temp); - include Extract_Phar::START; - } - $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); - if (!$pt || $pt == '/') { - $pt = $web; - header('HTTP/1.1 301 Moved Permanently'); - header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); +if ($web) { + if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { + Phar::interceptFileFuncs(); + Phar::webPhar(null, $web); + include 'phar://' . __FILE__ . '/' . Extract_Phar::START; + return; } - $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); - if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { - header('HTTP/1.0 404 Not Found'); - echo "\n \n File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>"; - exit; - } - $b = pathinfo($a); - if (!isset($b['extension'])) { - header('Content-Type: text/plain'); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; - } - if (isset($mimes[$b['extension']])) { - if ($mimes[$b['extension']] === 1) { - $_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO']; - $_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename)); - if (isset($_SERVER['PATH_TRANSLATED'])) { - $_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED']; - $_SERVER['PATH_TRANSLATED'] = $a; - } - include $a; + if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { + Extract_Phar::go(true); + $mimes = array( + 'phps' => 2, + 'c' => 'text/plain', + 'cc' => 'text/plain', + 'cpp' => 'text/plain', + 'c++' => 'text/plain', + 'dtd' => 'text/plain', + 'h' => 'text/plain', + 'log' => 'text/plain', + 'rng' => 'text/plain', + 'txt' => 'text/plain', + 'xsd' => 'text/plain', + 'php' => 1, + 'inc' => 1, + 'avi' => 'video/avi', + 'bmp' => 'image/bmp', + 'css' => 'text/css', + 'gif' => 'image/gif', + 'htm' => 'text/html', + 'html' => 'text/html', + 'htmls' => 'text/html', + 'ico' => 'image/x-ico', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'js' => 'application/x-javascript', + 'midi' => 'audio/midi', + 'mid' => 'audio/midi', + 'mod' => 'audio/mod', + 'mov' => 'movie/quicktime', + 'mp3' => 'audio/mp3', + 'mpg' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'pdf' => 'application/pdf', + 'png' => 'image/png', + 'swf' => 'application/shockwave-flash', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'wav' => 'audio/wav', + 'xbm' => 'image/xbm', + 'xml' => 'text/xml', + ); + $basename = basename(__FILE__); + if (!strpos($_SERVER['REQUEST_URI'], $basename)) { + chdir(Extract_Phar::$temp); + include Extract_Phar::START; + } + $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); + if (!$pt || $pt == '/') { + $pt = $web; + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); + } + $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); + if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { + header('HTTP/1.0 404 Not Found'); + echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>"; exit; } - if ($mimes[$b['extension']] === 2) { - highlight_file($a); + $b = pathinfo($a); + if (!isset($b['extension'])) { + header('Content-Type: text/plain'); + header('Content-Length: ' . filesize($a)); + readfile($a); + exit; + } + if (isset($mimes[$b['extension']])) { + if ($mimes[$b['extension']] === 1) { + $_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO']; + $_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename)); + if (isset($_SERVER['PATH_TRANSLATED'])) { + $_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED']; + $_SERVER['PATH_TRANSLATED'] = $a; + } + include $a; + exit; + } + if ($mimes[$b['extension']] === 2) { + highlight_file($a); + exit; + } + header('Content-Type: ' .$mimes[$b['extension']]); + header('Content-Length: ' . filesize($a)); + readfile($a); exit; } - header('Content-Type: ' .$mimes[$b['extension']]); - header('Content-Length: ' . filesize($a)); - readfile($a); - exit; } } if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { @@ -134,14 +136,14 @@ class Extract_Phar $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { - die('Error: zlib extension is not enabled - gzinflate() function needed' . - ' for compressed .phars'); + die('Error: zlib extension is not enabled -' . + ' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { - die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . - ' for compressed .phars'); + die('Error: bzip2 extension is not enabled -' . + ' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); @@ -149,7 +151,7 @@ class Extract_Phar $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); - if (!file_exists($sessionpath) && !is_dir($sessionpath)) { + if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; @@ -185,21 +187,15 @@ class Extract_Phar static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { - if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) { - return $var; - } - if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) { + if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } - if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) { - return $var; + if (is_dir('/temp') || mkdir('/temp')) { + return realpath('/temp'); } - if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { - return $var; - } - return @getenv('SystemRoot') . '\temp'; + return false; } - if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { + if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); @@ -255,18 +251,17 @@ class Extract_Phar $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { - die("Not valid internal .phar file (size error " . strlen($data) . " != " . + die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { - die("Not valid internal .phar file (checksum error)"); + die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles() { - // for removal of temp files if (count(self::$tmp)) { foreach (array_reverse(self::$tmp) as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); @@ -275,4 +270,4 @@ class Extract_Phar } chdir(self::$origdir); } -} \ No newline at end of file +} diff --git a/ext/phar/stub.h b/ext/phar/stub.h index b155c5c9c4..22f550b2c2 100644 --- a/ext/phar/stub.h +++ b/ext/phar/stub.h @@ -21,15 +21,14 @@ static inline void phar_get_stub(const char *index_php, const char *web, size_t *len, char **stub, const int name_len, const int web_len TSRMLS_DC) { static const char newstub0[] = "<?php\n$web = '"; - static const char newstub1_0[] = "';\nif ($web && in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nif ($web && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico' => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude Extract_Phar::START;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);\nif (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\necho \"<html>\\n <head>\\n <title>File Not Found<title>\\n </head>\\n <body>\\n <h1>404 - File \", $p"; - static const char newstub1_1[] = "t, \" Not Found</h1>\\n </body>\\n</html>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\n$_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO'];\n$_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename));\nif (isset($_SERVER['PATH_TRANSLATED'])) {\n$_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED'];\n$_SERVER['PATH_TRANSLATED'] = $a;\n}\ninclude $a;\nexit;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\nexit;\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nclass Extract_Phar\n{\nstatic $temp;\nstatic $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; + static const char newstub1_0[] = "';\nif ($web) {\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\nPhar::webPhar(null, $web);\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nif (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') {\nExtract_Phar::go(true);\n$mimes = array(\n'phps' => 2,\n'c' => 'text/plain',\n'cc' => 'text/plain',\n'cpp' => 'text/plain',\n'c++' => 'text/plain',\n'dtd' => 'text/plain',\n'h' => 'text/plain',\n'log' => 'text/plain',\n'rng' => 'text/plain',\n'txt' => 'text/plain',\n'xsd' => 'text/plain',\n'php' => 1,\n'inc' => 1,\n'avi' => 'video/avi',\n'bmp' => 'image/bmp',\n'css' => 'text/css',\n'gif' => 'image/gif',\n'htm' => 'text/html',\n'html' => 'text/html',\n'htmls' => 'text/html',\n'ico' => 'image/x-ico',\n'jpe' => 'image/jpeg',\n'jpg' => 'image/jpeg',\n'jpeg' => 'image/jpeg',\n'js' => 'application/x-javascript',\n'midi' => 'audio/midi',\n'mid' => 'audio/midi',\n'mod' => 'audio/mod',\n'mov' => 'movie/quicktime',\n'mp3' => 'audio/mp3',\n'mpg' => 'video/mpeg',\n'mpeg' => 'video/mpeg',\n'pdf' => 'application/pdf',\n'png' => 'image/png',\n'swf' => 'application/shockwave-flash',\n'tif' => 'image/tiff',\n'tiff' => 'image/tiff',\n'wav' => 'audio/wav',\n'xbm' => 'image/xbm',\n'xml' => 'text/xml',\n);\n$basename = basename(__FILE__);\nif (!strpos($_SERVER['REQUEST_URI'], $basename)) {\nchdir(Extract_Phar::$temp);\ninclude Extract_Phar::START;\n}\n$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));\nif (!$pt || $pt == '/') {\n$pt = $web;\nheader('HTTP/1.1 301 Moved Permanently');\nheader('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);\n}\n$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);\nif (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {\nheader('HTTP/1.0 404 Not Found');\necho \"<html>\\n <head>\\n <title>File Not Found<title>\\n </head>\\n <body>\\n <h1>404 - File \", $pt, "; + static const char newstub1_1[] = "\" Not Found</h1>\\n </body>\\n</html>\";\nexit;\n}\n$b = pathinfo($a);\nif (!isset($b['extension'])) {\nheader('Content-Type: text/plain');\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\nif (isset($mimes[$b['extension']])) {\nif ($mimes[$b['extension']] === 1) {\n$_SERVER['PHAR_PATH_INFO'] = $_SERVER['PATH_INFO'];\n$_SERVER['PATH_INFO'] = substr($_SERVER['PATH_INFO'], strpos($_SERVER['PATH_INFO'], $basename) + strlen($basename));\nif (isset($_SERVER['PATH_TRANSLATED'])) {\n$_SERVER['PHAR_PATH_TRANSLATED'] = $_SERVER['PATH_TRANSLATED'];\n$_SERVER['PATH_TRANSLATED'] = $a;\n}\ninclude $a;\nexit;\n}\nif ($mimes[$b['extension']] === 2) {\nhighlight_file($a);\nexit;\n}\nheader('Content-Type: ' .$mimes[$b['extension']]);\nheader('Content-Length: ' . filesize($a));\nreadfile($a);\nexit;\n}\n}\n}\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\ninclude 'phar://' . __FILE__ . '/' . Extract_Phar::START;\nreturn;\n}\nclass Extract_Phar\n{\nstatic $temp;\nstatic $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; static const char newstub2[] = "';\nconst LEN = "; - static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled - gzinflate() function needed' .\n' for compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled - bzdecompress() function needed' .\n' for compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$temp) {\n$sessionpath = session_save_path();\nif (strpos ($sessionpath, \";\") !== FALSE)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) && !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract';\nself::$temp = $temp;\nwhile (file_exists($temp)) {\n$temp .= 1;\n}\n@mkdir($temp);\n@chmod($temp, 0777);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\nself::$origdir = getcwd();\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path));\nif ($path[strlen($path) - 1] == '/') {\nmkdir($temp . '/' . $path);\n@chmod($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' . $path, 0666);\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir($temp);\nif (!$return) include self::START;\n}\n\nstatic function t"; - static const char newstub3_1[] = "mpdir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {\nreturn $var;\n}\nif ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {\nreturn $var;\n}\nif ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) {\nreturn $var;\n}\nif ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {\nreturn $var;\n}\nreturn @getenv('SystemRoot') . '\\temp';\n}\nif ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Not valid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($"; - static const char newstub3_2[] = "data) & 0xffffffff)) {\ndie(\"Not valid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles()\n{\n// for removal of temp files\nif (count(self::$tmp)) {\nforeach (array_reverse(self::$tmp) as $f) {\nif (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f);\n}\n\n}\nchdir(self::$origdir);\n}\n}\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; + static const char newstub3_0[] = ";\nstatic function go($return = false)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\ndo {\n$read = 8192;\nif ($L[1] - strlen($m) < 8192) {\n$read = $L[1] - strlen($m);\n}\n$last = fread($fp, $read);\n$m .= $last;\n} while (strlen($last) && strlen($m) < $L[1]);\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n$info = self::_unpack($m);\n$f = $info['c'];\nif ($f & self::GZ) {\nif (!function_exists('gzinflate')) {\ndie('Error: zlib extension is not enabled -' .\n' gzinflate() function needed for zlib-compressed .phars');\n}\n}\nif ($f & self::BZ2) {\nif (!function_exists('bzdecompress')) {\ndie('Error: bzip2 extension is not enabled -' .\n' bzdecompress() function needed for bz2-compressed .phars');\n}\n}\n$temp = self::tmpdir();\nif (!$temp) {\n$sessionpath = session_save_path();\nif (strpos ($sessionpath, \";\") !== FALSE)\n$sessionpath = substr ($sessionpath, strpos ($sessionpath, \";\")+1);\nif (!file_exists($sessionpath) || !is_dir($sessionpath)) {\ndie('Could not locate temporary directory to extract phar');\n}\n$temp = $sessionpath;\n}\n$temp .= '/pharextract';\nself::$temp = $temp;\nwhile (file_exists($temp)) {\n$temp .= 1;\n}\n@mkdir($temp);\n@chmod($temp, 0777);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\nself::$origdir = getcwd();\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\nif ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path));\nif ($path[strlen($path) - 1] == '/') {\nmkdir($temp . '/' . $path);\n@chmod($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' . $path, 0666);\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir($temp);\nif (!$return) include self::START;\n}\n\nstatic f"; + static const char newstub3_1[] = "unction tmpdir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {\nreturn $var;\n}\nif (is_dir('/temp') || mkdir('/temp')) {\nreturn realpath('/temp');\n}\nreturn false;\n}\nif ($var = getenv('TMPDIR')) {\nreturn $var;\n}\nreturn realpath('/tmp');\n}\n\nstatic function _unpack($m)\n{\n$info = unpack('V', substr($m, 0, 4));\n// skip API version, phar flags, alias, metadata\n$l = unpack('V', substr($m, 10, 4));\n$m = substr($m, 14 + $l[1]);\n$s = unpack('V', substr($m, 0, 4));\n$o = 0;\n$start = 4 + $s[1];\n$ret['c'] = 0;\nfor ($i = 0; $i < $info[1]; $i++) {\n// length of the file name\n$len = unpack('V', substr($m, $start, 4));\n$start += 4;\n// file name\n$savepath = substr($m, $start, $len[1]);\n$start += $len[1];\n// retrieve manifest data:\n// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags\n// 5 = metadata length\n$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));\n$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]\n& 0xffffffff);\n$ret['m'][$savepath][7] = $o;\n$o += $ret['m'][$savepath][2];\n$start += 24 + $ret['m'][$savepath][5];\n$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;\n}\nreturn $ret;\n}\n\nstatic function extractFile($path, $entry, $fp)\n{\n$data = '';\n$c = $entry[2];\nwhile ($c) {\nif ($c < 8192) {\n$data .= @fread($fp, $c);\n$c = 0;\n} else {\n$c -= 8192;\n$data .= @fread($fp, 8192);\n}\n}\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\nreturn $data;\n}\n\nstatic function _removeTmpFiles()\n{\nif (count(self::$tmp)) {\nforeach (array_reverse(self::$tmp) as $f) {\nif (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f);\n}\n\n}\n"; + static const char newstub3_2[] = "chdir(self::$origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>"; - - static const int newstub_len = 7406; + static const int newstub_len = 7100; *len = spprintf(stub, name_len + web_len + newstub_len, "%s%s%s%s%s%s%d%s%s%s", newstub0, web, newstub1_0, newstub1_1, index_php, newstub2, name_len + web_len + newstub_len, newstub3_0, newstub3_1, newstub3_2); } diff --git a/ext/phar/tests/031.phpt b/ext/phar/tests/031.phpt index ceb057bc60..54a44e401f 100755 --- a/ext/phar/tests/031.phpt +++ b/ext/phar/tests/031.phpt @@ -28,4 +28,4 @@ __halt_compiler(); --EXPECTF-- string(25) "<?php echo new new class;" -Parse error: %s error%s in phar://%sphar_oo_test.phar.php/a.php on line %d +Parse error: %s in phar://%sphar_oo_test.phar.php/a.php on line %d diff --git a/ext/phar/tests/phar_commitwrite.phpt b/ext/phar/tests/phar_commitwrite.phpt index b461a4ac45..17abadce9d 100644 --- a/ext/phar/tests/phar_commitwrite.phpt +++ b/ext/phar/tests/phar_commitwrite.phpt @@ -29,15 +29,16 @@ unlink(dirname(__FILE__) . '/brandnewphar.phar'); __HALT_COMPILER(); ?> --EXPECT-- -string(7416) "<?php +string(7110) "<?php $web = '0'; -if ($web && in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { +if ($web) { +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); Phar::webPhar(null, $web); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } -if ($web && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { +if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { Extract_Phar::go(true); $mimes = array( 'phps' => 2, @@ -126,6 +127,7 @@ readfile($a); exit; } } +} if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; @@ -140,7 +142,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'index.php'; -const LEN = 7416; +const LEN = 7110; static function go($return = false) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -165,14 +167,14 @@ $info = self::_unpack($m); $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { -die('Error: zlib extension is not enabled - gzinflate() function needed' . -' for compressed .phars'); +die('Error: zlib extension is not enabled -' . +' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { -die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . -' for compressed .phars'); +die('Error: bzip2 extension is not enabled -' . +' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); @@ -180,7 +182,7 @@ if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); -if (!file_exists($sessionpath) && !is_dir($sessionpath)) { +if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; @@ -216,21 +218,15 @@ if (!$return) include self::START; static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { -if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) { -return $var; -} -if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) { +if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } -if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) { -return $var; -} -if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { -return $var; +if (is_dir('/temp') || mkdir('/temp')) { +return realpath('/temp'); } -return @getenv('SystemRoot') . '\temp'; +return false; } -if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { +if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); @@ -286,18 +282,17 @@ $data = gzinflate($data); $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { -die("Not valid internal .phar file (size error " . strlen($data) . " != " . +die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { -die("Not valid internal .phar file (checksum error)"); +die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles() { -// for removal of temp files if (count(self::$tmp)) { foreach (array_reverse(self::$tmp) as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); @@ -307,6 +302,7 @@ if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); chdir(self::$origdir); } } + Extract_Phar::go(); __HALT_COMPILER(); ?>" string(200) "<?php diff --git a/ext/phar/tests/phar_create_in_cwd.phpt b/ext/phar/tests/phar_create_in_cwd.phpt index ece77d9aaf..f8e4b7f2a9 100644 --- a/ext/phar/tests/phar_create_in_cwd.phpt +++ b/ext/phar/tests/phar_create_in_cwd.phpt @@ -32,7 +32,7 @@ __HALT_COMPILER(); unlink(dirname(__FILE__) . '/brandnewphar.phar'); ?> --EXPECT-- -int(7416) +int(7110) string(200) "<?php function __autoload($class) { diff --git a/ext/phar/tests/phar_createdefaultstub.phpt b/ext/phar/tests/phar_createdefaultstub.phpt index 1d59fc2cbe..775923fe61 100644 --- a/ext/phar/tests/phar_createdefaultstub.phpt +++ b/ext/phar/tests/phar_createdefaultstub.phpt @@ -34,15 +34,16 @@ echo $e->getMessage() . "\n"; ?> ===DONE=== --EXPECT-- -string(7416) "<?php +string(7110) "<?php $web = '0'; -if ($web && in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { +if ($web) { +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); Phar::webPhar(null, $web); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } -if ($web && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { +if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { Extract_Phar::go(true); $mimes = array( 'phps' => 2, @@ -131,6 +132,7 @@ readfile($a); exit; } } +} if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; @@ -145,7 +147,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'index.php'; -const LEN = 7416; +const LEN = 7110; static function go($return = false) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -170,14 +172,14 @@ $info = self::_unpack($m); $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { -die('Error: zlib extension is not enabled - gzinflate() function needed' . -' for compressed .phars'); +die('Error: zlib extension is not enabled -' . +' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { -die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . -' for compressed .phars'); +die('Error: bzip2 extension is not enabled -' . +' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); @@ -185,7 +187,7 @@ if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); -if (!file_exists($sessionpath) && !is_dir($sessionpath)) { +if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; @@ -221,21 +223,15 @@ if (!$return) include self::START; static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { -if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) { -return $var; -} -if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) { -return $var; -} -if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) { +if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } -if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { -return $var; +if (is_dir('/temp') || mkdir('/temp')) { +return realpath('/temp'); } -return @getenv('SystemRoot') . '\temp'; +return false; } -if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { +if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); @@ -291,18 +287,17 @@ $data = gzinflate($data); $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { -die("Not valid internal .phar file (size error " . strlen($data) . " != " . +die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { -die("Not valid internal .phar file (checksum error)"); +die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles() { -// for removal of temp files if (count(self::$tmp)) { foreach (array_reverse(self::$tmp) as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); @@ -312,19 +307,21 @@ if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); chdir(self::$origdir); } } + Extract_Phar::go(); __HALT_COMPILER(); ?>" ============================================================================ ============================================================================ -string(7427) "<?php +string(7121) "<?php $web = '0'; -if ($web && in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { +if ($web) { +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); Phar::webPhar(null, $web); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } -if ($web && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { +if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { Extract_Phar::go(true); $mimes = array( 'phps' => 2, @@ -413,6 +410,7 @@ readfile($a); exit; } } +} if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; @@ -427,7 +425,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'my/custom/thingy.php'; -const LEN = 7428; +const LEN = 7122; static function go($return = false) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -452,14 +450,14 @@ $info = self::_unpack($m); $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { -die('Error: zlib extension is not enabled - gzinflate() function needed' . -' for compressed .phars'); +die('Error: zlib extension is not enabled -' . +' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { -die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . -' for compressed .phars'); +die('Error: bzip2 extension is not enabled -' . +' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); @@ -467,7 +465,7 @@ if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); -if (!file_exists($sessionpath) && !is_dir($sessionpath)) { +if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; @@ -503,21 +501,15 @@ if (!$return) include self::START; static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { -if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) { -return $var; -} -if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) { +if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } -if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) { -return $var; -} -if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { -return $var; +if (is_dir('/temp') || mkdir('/temp')) { +return realpath('/temp'); } -return @getenv('SystemRoot') . '\temp'; +return false; } -if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { +if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); @@ -573,18 +565,17 @@ $data = gzinflate($data); $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { -die("Not valid internal .phar file (size error " . strlen($data) . " != " . +die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { -die("Not valid internal .phar file (checksum error)"); +die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles() { -// for removal of temp files if (count(self::$tmp)) { foreach (array_reverse(self::$tmp) as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); @@ -594,11 +585,12 @@ if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); chdir(self::$origdir); } } + Extract_Phar::go(); __HALT_COMPILER(); ?>" ============================================================================ ============================================================================ -int(7807) +int(7501) ============================================================================ ============================================================================ Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed @@ -606,15 +598,16 @@ Illegal filename passed in for stub creation, was 401 characters long, and only ============================================================================ ============================================================================ ============================================================================ -string(7437) "<?php +string(7131) "<?php $web = 'the/web.php'; -if ($web && in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { +if ($web) { +if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); Phar::webPhar(null, $web); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } -if ($web && isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { +if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { Extract_Phar::go(true); $mimes = array( 'phps' => 2, @@ -703,6 +696,7 @@ readfile($a); exit; } } +} if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; @@ -717,7 +711,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'my/custom/thingy.php'; -const LEN = 7439; +const LEN = 7133; static function go($return = false) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -742,14 +736,14 @@ $info = self::_unpack($m); $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { -die('Error: zlib extension is not enabled - gzinflate() function needed' . -' for compressed .phars'); +die('Error: zlib extension is not enabled -' . +' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { -die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . -' for compressed .phars'); +die('Error: bzip2 extension is not enabled -' . +' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); @@ -757,7 +751,7 @@ if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); -if (!file_exists($sessionpath) && !is_dir($sessionpath)) { +if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; @@ -793,21 +787,15 @@ if (!$return) include self::START; static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { -if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) { +if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } -if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) { -return $var; -} -if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : @getenv('USERPROFILE')) { -return $var; +if (is_dir('/temp') || mkdir('/temp')) { +return realpath('/temp'); } -if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { -return $var; -} -return @getenv('SystemRoot') . '\temp'; +return false; } -if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { +if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); @@ -863,18 +851,17 @@ $data = gzinflate($data); $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { -die("Not valid internal .phar file (size error " . strlen($data) . " != " . +die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { -die("Not valid internal .phar file (checksum error)"); +die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles() { -// for removal of temp files if (count(self::$tmp)) { foreach (array_reverse(self::$tmp) as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); @@ -884,10 +871,11 @@ if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); chdir(self::$origdir); } } + Extract_Phar::go(); __HALT_COMPILER(); ?>" ============================================================================ ============================================================================ -int(7815) +int(7509) Illegal web filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed ===DONE=== \ No newline at end of file -- 2.40.0