1--TEST--
2Phar: Phar::createDefaultStub() with and without arg
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--FILE--
6<?php
7try {
8var_dump(Phar::createDefaultStub());
9echo "============================================================================\n";
10echo "============================================================================\n";
11var_dump(Phar::createDefaultStub('my/custom/thingy.php'));
12echo "============================================================================\n";
13echo "============================================================================\n";
14var_dump(strlen(Phar::createDefaultStub(str_repeat('a', 400))));
15echo "============================================================================\n";
16echo "============================================================================\n";
17var_dump(Phar::createDefaultStub(str_repeat('a', 401)));
18} catch(Exception $e) {
19echo $e->getMessage() . "\n";
20}
21echo "============================================================================\n";
22echo "============================================================================\n";
23echo "============================================================================\n";
24echo "============================================================================\n";
25try {
26var_dump(Phar::createDefaultStub('my/custom/thingy.php', 'the/web.php'));
27echo "============================================================================\n";
28echo "============================================================================\n";
29var_dump(strlen(Phar::createDefaultStub('index.php', str_repeat('a', 400))));
30var_dump(Phar::createDefaultStub('hio', str_repeat('a', 401)));
31} catch (Exception $e) {
32echo $e->getMessage() . "\n";
33}
34?>
35--EXPECT--
36string(6641) "<?php
37
38$web = 'index.php';
39
40if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
41Phar::interceptFileFuncs();
42set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
43Phar::webPhar(null, $web);
44include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
45return;
46}
47
48if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
49Extract_Phar::go(true);
50$mimes = array(
51'phps' => 2,
52'c' => 'text/plain',
53'cc' => 'text/plain',
54'cpp' => 'text/plain',
55'c++' => 'text/plain',
56'dtd' => 'text/plain',
57'h' => 'text/plain',
58'log' => 'text/plain',
59'rng' => 'text/plain',
60'txt' => 'text/plain',
61'xsd' => 'text/plain',
62'php' => 1,
63'inc' => 1,
64'avi' => 'video/avi',
65'bmp' => 'image/bmp',
66'css' => 'text/css',
67'gif' => 'image/gif',
68'htm' => 'text/html',
69'html' => 'text/html',
70'htmls' => 'text/html',
71'ico' => 'image/x-ico',
72'jpe' => 'image/jpeg',
73'jpg' => 'image/jpeg',
74'jpeg' => 'image/jpeg',
75'js' => 'application/x-javascript',
76'midi' => 'audio/midi',
77'mid' => 'audio/midi',
78'mod' => 'audio/mod',
79'mov' => 'movie/quicktime',
80'mp3' => 'audio/mp3',
81'mpg' => 'video/mpeg',
82'mpeg' => 'video/mpeg',
83'pdf' => 'application/pdf',
84'png' => 'image/png',
85'swf' => 'application/shockwave-flash',
86'tif' => 'image/tiff',
87'tiff' => 'image/tiff',
88'wav' => 'audio/wav',
89'xbm' => 'image/xbm',
90'xml' => 'text/xml',
91);
92
93header("Cache-Control: no-cache, must-revalidate");
94header("Pragma: no-cache");
95
96$basename = basename(__FILE__);
97if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
98chdir(Extract_Phar::$temp);
99include $web;
100return;
101}
102$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
103if (!$pt || $pt == '/') {
104$pt = $web;
105header('HTTP/1.1 301 Moved Permanently');
106header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
107exit;
108}
109$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
110if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
111header('HTTP/1.0 404 Not Found');
112echo "<html>\n <head>\n  <title>File Not Found<title>\n </head>\n <body>\n  <h1>404 - File Not Found</h1>\n </body>\n</html>";
113exit;
114}
115$b = pathinfo($a);
116if (!isset($b['extension'])) {
117header('Content-Type: text/plain');
118header('Content-Length: ' . filesize($a));
119readfile($a);
120exit;
121}
122if (isset($mimes[$b['extension']])) {
123if ($mimes[$b['extension']] === 1) {
124include $a;
125exit;
126}
127if ($mimes[$b['extension']] === 2) {
128highlight_file($a);
129exit;
130}
131header('Content-Type: ' .$mimes[$b['extension']]);
132header('Content-Length: ' . filesize($a));
133readfile($a);
134exit;
135}
136}
137
138class Extract_Phar
139{
140static $temp;
141static $origdir;
142const GZ = 0x1000;
143const BZ2 = 0x2000;
144const MASK = 0x3000;
145const START = 'index.php';
146const LEN = 6643;
147
148static function go($return = false)
149{
150$fp = fopen(__FILE__, 'rb');
151fseek($fp, self::LEN);
152$L = unpack('V', $a = fread($fp, 4));
153$m = '';
154
155do {
156$read = 8192;
157if ($L[1] - strlen($m) < 8192) {
158$read = $L[1] - strlen($m);
159}
160$last = fread($fp, $read);
161$m .= $last;
162} while (strlen($last) && strlen($m) < $L[1]);
163
164if (strlen($m) < $L[1]) {
165die('ERROR: manifest length read was "' .
166strlen($m) .'" should be "' .
167$L[1] . '"');
168}
169
170$info = self::_unpack($m);
171$f = $info['c'];
172
173if ($f & self::GZ) {
174if (!function_exists('gzinflate')) {
175die('Error: zlib extension is not enabled -' .
176' gzinflate() function needed for zlib-compressed .phars');
177}
178}
179
180if ($f & self::BZ2) {
181if (!function_exists('bzdecompress')) {
182die('Error: bzip2 extension is not enabled -' .
183' bzdecompress() function needed for bz2-compressed .phars');
184}
185}
186
187$temp = self::tmpdir();
188
189if (!$temp || !is_writable($temp)) {
190$sessionpath = session_save_path();
191if (strpos ($sessionpath, ";") !== false)
192$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
193if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
194die('Could not locate temporary directory to extract phar');
195}
196$temp = $sessionpath;
197}
198
199$temp .= '/pharextract/'.basename(__FILE__, '.phar');
200self::$temp = $temp;
201self::$origdir = getcwd();
202@mkdir($temp, 0777, true);
203$temp = realpath($temp);
204
205if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
206self::_removeTmpFiles($temp, getcwd());
207@mkdir($temp, 0777, true);
208@file_put_contents($temp . '/' . md5_file(__FILE__), '');
209
210foreach ($info['m'] as $path => $file) {
211$a = !file_exists(dirname($temp . '/' . $path));
212@mkdir(dirname($temp . '/' . $path), 0777, true);
213clearstatcache();
214
215if ($path[strlen($path) - 1] == '/') {
216@mkdir($temp . '/' . $path, 0777);
217} else {
218file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
219@chmod($temp . '/' . $path, 0666);
220}
221}
222}
223
224chdir($temp);
225
226if (!$return) {
227include self::START;
228}
229}
230
231static function tmpdir()
232{
233if (strpos(PHP_OS, 'WIN') !== false) {
234if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
235return $var;
236}
237if (is_dir('/temp') || mkdir('/temp')) {
238return realpath('/temp');
239}
240return false;
241}
242if ($var = getenv('TMPDIR')) {
243return $var;
244}
245return realpath('/tmp');
246}
247
248static function _unpack($m)
249{
250$info = unpack('V', substr($m, 0, 4));
251 $l = unpack('V', substr($m, 10, 4));
252$m = substr($m, 14 + $l[1]);
253$s = unpack('V', substr($m, 0, 4));
254$o = 0;
255$start = 4 + $s[1];
256$ret['c'] = 0;
257
258for ($i = 0; $i < $info[1]; $i++) {
259 $len = unpack('V', substr($m, $start, 4));
260$start += 4;
261 $savepath = substr($m, $start, $len[1]);
262$start += $len[1];
263   $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
264$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
265& 0xffffffff);
266$ret['m'][$savepath][7] = $o;
267$o += $ret['m'][$savepath][2];
268$start += 24 + $ret['m'][$savepath][5];
269$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
270}
271return $ret;
272}
273
274static function extractFile($path, $entry, $fp)
275{
276$data = '';
277$c = $entry[2];
278
279while ($c) {
280if ($c < 8192) {
281$data .= @fread($fp, $c);
282$c = 0;
283} else {
284$c -= 8192;
285$data .= @fread($fp, 8192);
286}
287}
288
289if ($entry[4] & self::GZ) {
290$data = gzinflate($data);
291} elseif ($entry[4] & self::BZ2) {
292$data = bzdecompress($data);
293}
294
295if (strlen($data) != $entry[0]) {
296die("Invalid internal .phar file (size error " . strlen($data) . " != " .
297$stat[7] . ")");
298}
299
300if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
301die("Invalid internal .phar file (checksum error)");
302}
303
304return $data;
305}
306
307static function _removeTmpFiles($temp, $origdir)
308{
309chdir($temp);
310
311foreach (glob('*') as $f) {
312if (file_exists($f)) {
313is_dir($f) ? @rmdir($f) : @unlink($f);
314if (file_exists($f) && is_dir($f)) {
315self::_removeTmpFiles($f, getcwd());
316}
317}
318}
319
320@rmdir($temp);
321clearstatcache();
322chdir($origdir);
323}
324}
325
326Extract_Phar::go();
327__HALT_COMPILER(); ?>"
328============================================================================
329============================================================================
330string(6652) "<?php
331
332$web = 'index.php';
333
334if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
335Phar::interceptFileFuncs();
336set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
337Phar::webPhar(null, $web);
338include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
339return;
340}
341
342if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
343Extract_Phar::go(true);
344$mimes = array(
345'phps' => 2,
346'c' => 'text/plain',
347'cc' => 'text/plain',
348'cpp' => 'text/plain',
349'c++' => 'text/plain',
350'dtd' => 'text/plain',
351'h' => 'text/plain',
352'log' => 'text/plain',
353'rng' => 'text/plain',
354'txt' => 'text/plain',
355'xsd' => 'text/plain',
356'php' => 1,
357'inc' => 1,
358'avi' => 'video/avi',
359'bmp' => 'image/bmp',
360'css' => 'text/css',
361'gif' => 'image/gif',
362'htm' => 'text/html',
363'html' => 'text/html',
364'htmls' => 'text/html',
365'ico' => 'image/x-ico',
366'jpe' => 'image/jpeg',
367'jpg' => 'image/jpeg',
368'jpeg' => 'image/jpeg',
369'js' => 'application/x-javascript',
370'midi' => 'audio/midi',
371'mid' => 'audio/midi',
372'mod' => 'audio/mod',
373'mov' => 'movie/quicktime',
374'mp3' => 'audio/mp3',
375'mpg' => 'video/mpeg',
376'mpeg' => 'video/mpeg',
377'pdf' => 'application/pdf',
378'png' => 'image/png',
379'swf' => 'application/shockwave-flash',
380'tif' => 'image/tiff',
381'tiff' => 'image/tiff',
382'wav' => 'audio/wav',
383'xbm' => 'image/xbm',
384'xml' => 'text/xml',
385);
386
387header("Cache-Control: no-cache, must-revalidate");
388header("Pragma: no-cache");
389
390$basename = basename(__FILE__);
391if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
392chdir(Extract_Phar::$temp);
393include $web;
394return;
395}
396$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
397if (!$pt || $pt == '/') {
398$pt = $web;
399header('HTTP/1.1 301 Moved Permanently');
400header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
401exit;
402}
403$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
404if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
405header('HTTP/1.0 404 Not Found');
406echo "<html>\n <head>\n  <title>File Not Found<title>\n </head>\n <body>\n  <h1>404 - File Not Found</h1>\n </body>\n</html>";
407exit;
408}
409$b = pathinfo($a);
410if (!isset($b['extension'])) {
411header('Content-Type: text/plain');
412header('Content-Length: ' . filesize($a));
413readfile($a);
414exit;
415}
416if (isset($mimes[$b['extension']])) {
417if ($mimes[$b['extension']] === 1) {
418include $a;
419exit;
420}
421if ($mimes[$b['extension']] === 2) {
422highlight_file($a);
423exit;
424}
425header('Content-Type: ' .$mimes[$b['extension']]);
426header('Content-Length: ' . filesize($a));
427readfile($a);
428exit;
429}
430}
431
432class Extract_Phar
433{
434static $temp;
435static $origdir;
436const GZ = 0x1000;
437const BZ2 = 0x2000;
438const MASK = 0x3000;
439const START = 'my/custom/thingy.php';
440const LEN = 6654;
441
442static function go($return = false)
443{
444$fp = fopen(__FILE__, 'rb');
445fseek($fp, self::LEN);
446$L = unpack('V', $a = fread($fp, 4));
447$m = '';
448
449do {
450$read = 8192;
451if ($L[1] - strlen($m) < 8192) {
452$read = $L[1] - strlen($m);
453}
454$last = fread($fp, $read);
455$m .= $last;
456} while (strlen($last) && strlen($m) < $L[1]);
457
458if (strlen($m) < $L[1]) {
459die('ERROR: manifest length read was "' .
460strlen($m) .'" should be "' .
461$L[1] . '"');
462}
463
464$info = self::_unpack($m);
465$f = $info['c'];
466
467if ($f & self::GZ) {
468if (!function_exists('gzinflate')) {
469die('Error: zlib extension is not enabled -' .
470' gzinflate() function needed for zlib-compressed .phars');
471}
472}
473
474if ($f & self::BZ2) {
475if (!function_exists('bzdecompress')) {
476die('Error: bzip2 extension is not enabled -' .
477' bzdecompress() function needed for bz2-compressed .phars');
478}
479}
480
481$temp = self::tmpdir();
482
483if (!$temp || !is_writable($temp)) {
484$sessionpath = session_save_path();
485if (strpos ($sessionpath, ";") !== false)
486$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
487if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
488die('Could not locate temporary directory to extract phar');
489}
490$temp = $sessionpath;
491}
492
493$temp .= '/pharextract/'.basename(__FILE__, '.phar');
494self::$temp = $temp;
495self::$origdir = getcwd();
496@mkdir($temp, 0777, true);
497$temp = realpath($temp);
498
499if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
500self::_removeTmpFiles($temp, getcwd());
501@mkdir($temp, 0777, true);
502@file_put_contents($temp . '/' . md5_file(__FILE__), '');
503
504foreach ($info['m'] as $path => $file) {
505$a = !file_exists(dirname($temp . '/' . $path));
506@mkdir(dirname($temp . '/' . $path), 0777, true);
507clearstatcache();
508
509if ($path[strlen($path) - 1] == '/') {
510@mkdir($temp . '/' . $path, 0777);
511} else {
512file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
513@chmod($temp . '/' . $path, 0666);
514}
515}
516}
517
518chdir($temp);
519
520if (!$return) {
521include self::START;
522}
523}
524
525static function tmpdir()
526{
527if (strpos(PHP_OS, 'WIN') !== false) {
528if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
529return $var;
530}
531if (is_dir('/temp') || mkdir('/temp')) {
532return realpath('/temp');
533}
534return false;
535}
536if ($var = getenv('TMPDIR')) {
537return $var;
538}
539return realpath('/tmp');
540}
541
542static function _unpack($m)
543{
544$info = unpack('V', substr($m, 0, 4));
545 $l = unpack('V', substr($m, 10, 4));
546$m = substr($m, 14 + $l[1]);
547$s = unpack('V', substr($m, 0, 4));
548$o = 0;
549$start = 4 + $s[1];
550$ret['c'] = 0;
551
552for ($i = 0; $i < $info[1]; $i++) {
553 $len = unpack('V', substr($m, $start, 4));
554$start += 4;
555 $savepath = substr($m, $start, $len[1]);
556$start += $len[1];
557   $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
558$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
559& 0xffffffff);
560$ret['m'][$savepath][7] = $o;
561$o += $ret['m'][$savepath][2];
562$start += 24 + $ret['m'][$savepath][5];
563$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
564}
565return $ret;
566}
567
568static function extractFile($path, $entry, $fp)
569{
570$data = '';
571$c = $entry[2];
572
573while ($c) {
574if ($c < 8192) {
575$data .= @fread($fp, $c);
576$c = 0;
577} else {
578$c -= 8192;
579$data .= @fread($fp, 8192);
580}
581}
582
583if ($entry[4] & self::GZ) {
584$data = gzinflate($data);
585} elseif ($entry[4] & self::BZ2) {
586$data = bzdecompress($data);
587}
588
589if (strlen($data) != $entry[0]) {
590die("Invalid internal .phar file (size error " . strlen($data) . " != " .
591$stat[7] . ")");
592}
593
594if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
595die("Invalid internal .phar file (checksum error)");
596}
597
598return $data;
599}
600
601static function _removeTmpFiles($temp, $origdir)
602{
603chdir($temp);
604
605foreach (glob('*') as $f) {
606if (file_exists($f)) {
607is_dir($f) ? @rmdir($f) : @unlink($f);
608if (file_exists($f) && is_dir($f)) {
609self::_removeTmpFiles($f, getcwd());
610}
611}
612}
613
614@rmdir($temp);
615clearstatcache();
616chdir($origdir);
617}
618}
619
620Extract_Phar::go();
621__HALT_COMPILER(); ?>"
622============================================================================
623============================================================================
624int(7032)
625============================================================================
626============================================================================
627Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
628============================================================================
629============================================================================
630============================================================================
631============================================================================
632string(6654) "<?php
633
634$web = 'the/web.php';
635
636if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
637Phar::interceptFileFuncs();
638set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
639Phar::webPhar(null, $web);
640include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
641return;
642}
643
644if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
645Extract_Phar::go(true);
646$mimes = array(
647'phps' => 2,
648'c' => 'text/plain',
649'cc' => 'text/plain',
650'cpp' => 'text/plain',
651'c++' => 'text/plain',
652'dtd' => 'text/plain',
653'h' => 'text/plain',
654'log' => 'text/plain',
655'rng' => 'text/plain',
656'txt' => 'text/plain',
657'xsd' => 'text/plain',
658'php' => 1,
659'inc' => 1,
660'avi' => 'video/avi',
661'bmp' => 'image/bmp',
662'css' => 'text/css',
663'gif' => 'image/gif',
664'htm' => 'text/html',
665'html' => 'text/html',
666'htmls' => 'text/html',
667'ico' => 'image/x-ico',
668'jpe' => 'image/jpeg',
669'jpg' => 'image/jpeg',
670'jpeg' => 'image/jpeg',
671'js' => 'application/x-javascript',
672'midi' => 'audio/midi',
673'mid' => 'audio/midi',
674'mod' => 'audio/mod',
675'mov' => 'movie/quicktime',
676'mp3' => 'audio/mp3',
677'mpg' => 'video/mpeg',
678'mpeg' => 'video/mpeg',
679'pdf' => 'application/pdf',
680'png' => 'image/png',
681'swf' => 'application/shockwave-flash',
682'tif' => 'image/tiff',
683'tiff' => 'image/tiff',
684'wav' => 'audio/wav',
685'xbm' => 'image/xbm',
686'xml' => 'text/xml',
687);
688
689header("Cache-Control: no-cache, must-revalidate");
690header("Pragma: no-cache");
691
692$basename = basename(__FILE__);
693if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
694chdir(Extract_Phar::$temp);
695include $web;
696return;
697}
698$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
699if (!$pt || $pt == '/') {
700$pt = $web;
701header('HTTP/1.1 301 Moved Permanently');
702header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
703exit;
704}
705$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
706if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
707header('HTTP/1.0 404 Not Found');
708echo "<html>\n <head>\n  <title>File Not Found<title>\n </head>\n <body>\n  <h1>404 - File Not Found</h1>\n </body>\n</html>";
709exit;
710}
711$b = pathinfo($a);
712if (!isset($b['extension'])) {
713header('Content-Type: text/plain');
714header('Content-Length: ' . filesize($a));
715readfile($a);
716exit;
717}
718if (isset($mimes[$b['extension']])) {
719if ($mimes[$b['extension']] === 1) {
720include $a;
721exit;
722}
723if ($mimes[$b['extension']] === 2) {
724highlight_file($a);
725exit;
726}
727header('Content-Type: ' .$mimes[$b['extension']]);
728header('Content-Length: ' . filesize($a));
729readfile($a);
730exit;
731}
732}
733
734class Extract_Phar
735{
736static $temp;
737static $origdir;
738const GZ = 0x1000;
739const BZ2 = 0x2000;
740const MASK = 0x3000;
741const START = 'my/custom/thingy.php';
742const LEN = 6656;
743
744static function go($return = false)
745{
746$fp = fopen(__FILE__, 'rb');
747fseek($fp, self::LEN);
748$L = unpack('V', $a = fread($fp, 4));
749$m = '';
750
751do {
752$read = 8192;
753if ($L[1] - strlen($m) < 8192) {
754$read = $L[1] - strlen($m);
755}
756$last = fread($fp, $read);
757$m .= $last;
758} while (strlen($last) && strlen($m) < $L[1]);
759
760if (strlen($m) < $L[1]) {
761die('ERROR: manifest length read was "' .
762strlen($m) .'" should be "' .
763$L[1] . '"');
764}
765
766$info = self::_unpack($m);
767$f = $info['c'];
768
769if ($f & self::GZ) {
770if (!function_exists('gzinflate')) {
771die('Error: zlib extension is not enabled -' .
772' gzinflate() function needed for zlib-compressed .phars');
773}
774}
775
776if ($f & self::BZ2) {
777if (!function_exists('bzdecompress')) {
778die('Error: bzip2 extension is not enabled -' .
779' bzdecompress() function needed for bz2-compressed .phars');
780}
781}
782
783$temp = self::tmpdir();
784
785if (!$temp || !is_writable($temp)) {
786$sessionpath = session_save_path();
787if (strpos ($sessionpath, ";") !== false)
788$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
789if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
790die('Could not locate temporary directory to extract phar');
791}
792$temp = $sessionpath;
793}
794
795$temp .= '/pharextract/'.basename(__FILE__, '.phar');
796self::$temp = $temp;
797self::$origdir = getcwd();
798@mkdir($temp, 0777, true);
799$temp = realpath($temp);
800
801if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
802self::_removeTmpFiles($temp, getcwd());
803@mkdir($temp, 0777, true);
804@file_put_contents($temp . '/' . md5_file(__FILE__), '');
805
806foreach ($info['m'] as $path => $file) {
807$a = !file_exists(dirname($temp . '/' . $path));
808@mkdir(dirname($temp . '/' . $path), 0777, true);
809clearstatcache();
810
811if ($path[strlen($path) - 1] == '/') {
812@mkdir($temp . '/' . $path, 0777);
813} else {
814file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
815@chmod($temp . '/' . $path, 0666);
816}
817}
818}
819
820chdir($temp);
821
822if (!$return) {
823include self::START;
824}
825}
826
827static function tmpdir()
828{
829if (strpos(PHP_OS, 'WIN') !== false) {
830if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
831return $var;
832}
833if (is_dir('/temp') || mkdir('/temp')) {
834return realpath('/temp');
835}
836return false;
837}
838if ($var = getenv('TMPDIR')) {
839return $var;
840}
841return realpath('/tmp');
842}
843
844static function _unpack($m)
845{
846$info = unpack('V', substr($m, 0, 4));
847 $l = unpack('V', substr($m, 10, 4));
848$m = substr($m, 14 + $l[1]);
849$s = unpack('V', substr($m, 0, 4));
850$o = 0;
851$start = 4 + $s[1];
852$ret['c'] = 0;
853
854for ($i = 0; $i < $info[1]; $i++) {
855 $len = unpack('V', substr($m, $start, 4));
856$start += 4;
857 $savepath = substr($m, $start, $len[1]);
858$start += $len[1];
859   $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
860$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
861& 0xffffffff);
862$ret['m'][$savepath][7] = $o;
863$o += $ret['m'][$savepath][2];
864$start += 24 + $ret['m'][$savepath][5];
865$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
866}
867return $ret;
868}
869
870static function extractFile($path, $entry, $fp)
871{
872$data = '';
873$c = $entry[2];
874
875while ($c) {
876if ($c < 8192) {
877$data .= @fread($fp, $c);
878$c = 0;
879} else {
880$c -= 8192;
881$data .= @fread($fp, 8192);
882}
883}
884
885if ($entry[4] & self::GZ) {
886$data = gzinflate($data);
887} elseif ($entry[4] & self::BZ2) {
888$data = bzdecompress($data);
889}
890
891if (strlen($data) != $entry[0]) {
892die("Invalid internal .phar file (size error " . strlen($data) . " != " .
893$stat[7] . ")");
894}
895
896if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
897die("Invalid internal .phar file (checksum error)");
898}
899
900return $data;
901}
902
903static function _removeTmpFiles($temp, $origdir)
904{
905chdir($temp);
906
907foreach (glob('*') as $f) {
908if (file_exists($f)) {
909is_dir($f) ? @rmdir($f) : @unlink($f);
910if (file_exists($f) && is_dir($f)) {
911self::_removeTmpFiles($f, getcwd());
912}
913}
914}
915
916@rmdir($temp);
917clearstatcache();
918chdir($origdir);
919}
920}
921
922Extract_Phar::go();
923__HALT_COMPILER(); ?>"
924============================================================================
925============================================================================
926int(7032)
927Illegal web filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
928