cvs: pecl /phar makestub.php phar.c phar_internal.h phar_object.c shortarc.php stub.h /phar/tests nophar.phar phar_commitwrite.phpt
phar_create_in_cwd.phpt phar_createdefaultstub.phpt

From: Date: Sat, 19 Jan 2008 04:26:21 +0000
Subject: cvs: pecl /phar makestub.php phar.c phar_internal.h phar_object.c shortarc.php stub.h /phar/tests nophar.phar phar_commitwrite.phpt
phar_create_in_cwd.phpt phar_createdefaultstub.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-9562@lists.php.net to get a copy of this message
cellog Sat Jan 19 04:26:21 2008 UTC Added files: /pecl/phar/tests phar_createdefaultstub.phpt Modified files: /pecl/phar makestub.php phar.c phar_internal.h phar_object.c shortarc.php stub.h /pecl/phar/tests nophar.phar phar_commitwrite.phpt phar_create_in_cwd.phpt Log: add Phar::createDefaultStub(), which can take as an argument the filename that should be loaded as a "bootstrap" for the phar archive

http://cvs.php.net/viewvc.cgi/pecl/phar/makestub.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/phar/makestub.php diff -u pecl/phar/makestub.php:1.1 pecl/phar/makestub.php:1.2 --- pecl/phar/makestub.php:1.1 Fri Jan 18 05:42:15 2008 +++ pecl/phar/makestub.php Sat Jan 19 04:26:21 2008 @@ -1,5 +1,6 @@ <?php $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php')); + $s .= "\nExtract_Phar::go(XXXX);\n__HALT_COMPILER();"; $news = ''; $last = -1; @@ -20,9 +21,14 @@ } } $s = $news . ' ?>'; -$s = str_replace('XXXX', strlen($s)-1, $s); +$slen = strlen($s) - strlen('index.php'); +//$s = str_replace('XXXX', strlen($s)-1, $s); $s = str_replace('"', '\\"', $s); $s = str_replace("\n", '\n', $s); +$s1 = substr($s, 0, strpos($s, 'index.php')); +$s2 = substr($s, strlen($s1) + strlen('index.php')); +$s2 = substr($s2, 0, strpos($s2, 'XXXX')); +$s3 = substr($s, strlen($s2) + 4 + strlen($s1) + strlen('index.php')); $stub = '/* +----------------------------------------------------------------------+ @@ -42,9 +48,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: makestub.php,v 1.1 2008/01/18 05:42:15 cellog Exp $ */ +/* $Id: makestub.php,v 1.2 2008/01/19 04:26:21 cellog Exp $ */ -static const char newstub[] = "' . $s . '"; +static const char newstub1[] = "' . $s1 . '"; +static const char newstub2[] = "' . $s2 . '"; +static const char newstub3[] = "' . $s3 . '"; +static const int newstub_len = ' . $slen . '; '; file_put_contents(dirname(__FILE__) . '/stub.h', $stub); http://cvs.php.net/viewvc.cgi/pecl/phar/phar.c?r1=1.277&r2=1.278&diff_format=u Index: pecl/phar/phar.c diff -u pecl/phar/phar.c:1.277 pecl/phar/phar.c:1.278 --- pecl/phar/phar.c:1.277 Fri Jan 18 05:42:15 2008 +++ pecl/phar/phar.c Sat Jan 19 04:26:21 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar.c,v 1.277 2008/01/18 05:42:15 cellog Exp $ */ +/* $Id: phar.c,v 1.278 2008/01/19 04:26:21 cellog Exp $ */ #define PHAR_MAIN 1 #include "phar_internal.h" @@ -2335,6 +2335,39 @@ } /* }}} */ +char *phar_create_default_stub(const char *index_php, size_t *len, char **error TSRMLS_DC) +{ +#include "stub.h" + char *stub = NULL; + static const char def[] = "index.php"; + int name_len; + size_t dummy; + + if (!len) { + len = &dummy; + } + + if (index_php) { + name_len = strlen(index_php); + } + if (error) { + *error = NULL; + } + if (index_php && name_len > 400) { + /* ridiculous big not allowed for index.php startup filename */ + if (error) { + spprintf(error, 0, "Illegal filename passed in for stub creation, was %d characters long, and only 400 or less is allowed", name_len); + return NULL; + } + } + if (!index_php) { + *len = spprintf(&stub, sizeof("index.php")-1 + newstub_len - 1, "%s%s%s%d%s", newstub1, def, newstub2, (int) sizeof("index.php")-1 + newstub_len - 1, newstub3); + } else { + *len = spprintf(&stub, name_len + newstub_len - 1, "%s%s%s%d%s", newstub1, index_php, newstub2, name_len + newstub_len - 1, newstub3); + } + return stub; +} + /** * Save phar contents to disk * @@ -2343,8 +2376,8 @@ */ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error TSRMLS_DC) /* {{{ */ { -#include "stub.h" /* static const char newstub[] = "<?php __HALT_COMPILER(); ?>\r\n"; */ + char *newstub; phar_entry_info *entry, *newentry; int halt_offset, restore_alias_len, global_flags = 0, closeoldfile; char *buf, *pos; @@ -2475,8 +2508,9 @@ } } else { /* this is a brand new phar */ - phar->halt_offset = sizeof(newstub)-1; - if (sizeof(newstub)-1 != php_stream_write(newfile, newstub, sizeof(newstub)-1)) { + newstub = phar_create_default_stub(NULL, &(phar->halt_offset), NULL TSRMLS_CC); + if (phar->halt_offset != php_stream_write(newfile, newstub, phar->halt_offset)) { + efree(newstub); if (closeoldfile) { php_stream_close(oldfile); } @@ -2486,6 +2520,7 @@ } return EOF; } + efree(newstub); } } manifest_ftell = php_stream_tell(newfile); @@ -3286,7 +3321,7 @@ php_info_print_table_header(2, "Phar: PHP Archive support", "enabled"); php_info_print_table_row(2, "Phar EXT version", PHAR_EXT_VERSION_STR); php_info_print_table_row(2, "Phar API version", PHAR_API_VERSION_STR); - php_info_print_table_row(2, "CVS revision", "$Revision: 1.277 $"); + php_info_print_table_row(2, "CVS revision", "$Revision: 1.278 $"); php_info_print_table_row(2, "Phar-based phar archives", "enabled"); php_info_print_table_row(2, "Tar-based phar archives", "enabled"); #if HAVE_PHAR_ZIP http://cvs.php.net/viewvc.cgi/pecl/phar/phar_internal.h?r1=1.66&r2=1.67&diff_format=u Index: pecl/phar/phar_internal.h diff -u pecl/phar/phar_internal.h:1.66 pecl/phar/phar_internal.h:1.67 --- pecl/phar/phar_internal.h:1.66 Fri Jan 18 05:42:15 2008 +++ pecl/phar/phar_internal.h Sat Jan 19 04:26:21 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_internal.h,v 1.66 2008/01/18 05:42:15 cellog Exp $ */ +/* $Id: phar_internal.h,v 1.67 2008/01/19 04:26:21 cellog Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -333,6 +333,7 @@ int phar_open_compiled_file(char *alias, int alias_len, char **error TSRMLS_DC); int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error TSRMLS_DC); int phar_open_loaded(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC); +char *phar_create_default_stub(const char *index_php, size_t *len, char **error TSRMLS_DC); char *phar_fix_filepath(char *path, int *new_len, int use_cwd TSRMLS_DC); phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, php_stream *fp, http://cvs.php.net/viewvc.cgi/pecl/phar/phar_object.c?r1=1.129&r2=1.130&diff_format=u Index: pecl/phar/phar_object.c diff -u pecl/phar/phar_object.c:1.129 pecl/phar/phar_object.c:1.130 --- pecl/phar/phar_object.c:1.129 Thu Jan 17 03:59:06 2008 +++ pecl/phar/phar_object.c Sat Jan 19 04:26:21 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_object.c,v 1.129 2008/01/17 03:59:06 cellog Exp $ */ +/* $Id: phar_object.c,v 1.130 2008/01/19 04:26:21 cellog Exp $ */ #include "phar_internal.h" #include "func_interceptors.h" @@ -735,6 +735,28 @@ } /* }}} */ +/* {{ proto array Phar::createDefaultStub([string indexfile]) + * Return a stub that can be used to run a phar-based archive without the phar extension + * indexfile is the startup filename, which defaults to "index.php" + */ +PHP_METHOD(Phar, createDefaultStub) +{ + char *index = NULL, *error; + int index_len; + size_t stub_len; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &index, &index_len) == FAILURE) { + return; + } + + index = phar_create_default_stub(index, &stub_len, &error TSRMLS_CC); + if (error) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, error); + efree(error); + return; + } + RETURN_STRINGL(index, stub_len, 0); +} + /* {{{ proto mixed Phar::mapPhar([string alias, [int dataoffset]]) * Reads the currently executed file (a phar) and registers its manifest */ PHP_METHOD(Phar, mapPhar) @@ -3385,6 +3407,11 @@ ZEND_END_ARG_INFO(); static +ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_cDS, 0, 0, 0) + ZEND_ARG_INFO(0, index_php) +ZEND_END_ARG_INFO(); + +static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setStub, 0, 0, 1) ZEND_ARG_INFO(0, newstub) ZEND_ARG_INFO(0, maxlen) @@ -3483,6 +3510,7 @@ PHP_ME(Phar, getSupportedSignatures,NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL) PHP_ME(Phar, getSupportedCompression,NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL) PHP_ME(Phar, isValidPharFilename, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL) + PHP_ME(Phar, createDefaultStub, arginfo_phar_cDS, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; http://cvs.php.net/viewvc.cgi/pecl/phar/shortarc.php?r1=1.1&r2=1.2&diff_format=u Index: pecl/phar/shortarc.php diff -u pecl/phar/shortarc.php:1.1 pecl/phar/shortarc.php:1.2 --- pecl/phar/shortarc.php:1.1 Fri Jan 18 05:42:15 2008 +++ pecl/phar/shortarc.php Sat Jan 19 04:26:21 2008 @@ -1,7 +1,7 @@ <?php if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); - include 'phar://' . __FILE__ . '/index.php'; + include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } class Extract_Phar @@ -11,6 +11,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; + const START = 'index.php'; static function go($D) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -75,7 +76,7 @@ self::$tmp[] = realpath($temp . '/' . $path); } chdir($temp); - include 'index.php'; + include self::START; } static function tmpdir() http://cvs.php.net/viewvc.cgi/pecl/phar/stub.h?r1=1.1&r2=1.2&diff_format=u Index: pecl/phar/stub.h diff -u pecl/phar/stub.h:1.1 pecl/phar/stub.h:1.2 --- pecl/phar/stub.h:1.1 Fri Jan 18 05:42:15 2008 +++ pecl/phar/stub.h Sat Jan 19 04:26:21 2008 @@ -16,6 +16,9 @@ +----------------------------------------------------------------------+ */ -/* $Id: stub.h,v 1.1 2008/01/18 05:42:15 cellog Exp $ */ +/* $Id: stub.h,v 1.2 2008/01/19 04:26:21 cellog Exp $ */ -static const char newstub[] = "<?php\nif (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {\nPhar::interceptFileFuncs();\ninclude 'phar://' . __FILE__ . '/index.php';\nreturn;\n}\nclass Extract_Phar\n{\nstatic $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nstatic function go($D)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, $D);\n$L = unpack('V', 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';\nif (!file_exists($temp)) {\n@mkdir($temp);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\n}\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} else {\nfile_put_contents($temp . '/' . $pat h, self::extractFile($path, $file, $fp));\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir($temp);\ninclude 'index.php';\n}\n\nstatic function tmpdir()\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] & sel! f::BZ2) {\n$data = bzdecompress($data);\n}\nif (strlen($data) != $entr y[0]) {\ndie(\"Not valid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\nif ($entry[3] != sprintf(\"%u\", crc32($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\nusort(self::$tmp, 'strnatcasecmp');\narray_reverse(self::$tmp, 1);\nif (count(self::$tmp)) {\nforeach (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(4461);\n__HALT_COMPILER(); ?>"; +static const char newstub1[] = "<?php\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 $tmp = array();\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '"; +static const char newstub2[] = "';\nstatic function go($D)\n{\nregister_shutdown_function(array('Extract_Phar', '_removeTmpFiles'));\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, $D);\n$L = unpack('V', 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_p! ath();\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';\nif (!file_exists($temp)) {\n@mkdir($temp);\n$temp = realpath($temp);\nself::$tmp[] = $temp;\n}\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} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n}\nself::$tmp[] = realpath($temp . '/' . $path);\n}\nchdir($temp);\ninclude self::START;\n}\n\nstatic function tmpdir()\n{\nif (strpos(PHP_OS, 'WIN') !== false) {\nif ($var = isse! t($_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 = compre! ssed 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($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\nusort(self::$tmp, 'strnatcasecmp');\narray_reverse(self::$tmp, 1);\nif (count(self::$tmp)) {\nforeach (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("; +static const char newstub3[] = ");\n__HALT_COMPILER(); ?>"; +static const int newstub_len = 4493; http://cvs.php.net/viewvc.cgi/pecl/phar/tests/nophar.phar?r1=1.1&r2=1.2&diff_format=u Index: pecl/phar/tests/nophar.phar diff -u pecl/phar/tests/nophar.phar:1.1 pecl/phar/tests/nophar.phar:1.2 --- pecl/phar/tests/nophar.phar:1.1 Fri Jan 18 05:42:15 2008 +++ pecl/phar/tests/nophar.phar Sat Jan 19 04:26:21 2008 @@ -1,7 +1,7 @@ <?php if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); -include 'phar://' . __FILE__ . '/index.php'; +include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } class Extract_Phar @@ -11,6 +11,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; +const START = 'index.php'; static function go($D) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -75,7 +76,7 @@ self::$tmp[] = realpath($temp . '/' . $path); } chdir($temp); -include 'index.php'; +include self::START; } static function tmpdir() @@ -174,7 +175,8 @@ chdir(self::$origdir); } } -Extract_Phar::go(4461); -__HALT_COMPILER(); ?>w+Extract_Phar::go(4501); +__HALT_COMPILER(); ?>w <?php echo "in b\n";$a = fopen("index.php", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";in d -M gqì™:í[Mo€ …[° \ No newline at end of file +õL׼ۆ 9 +g=ÃLõ¬äև\ No newline at end of file http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_commitwrite.phpt?r1=1.8&r2=1.9&diff_format=u Index: pecl/phar/tests/phar_commitwrite.phpt diff -u pecl/phar/tests/phar_commitwrite.phpt:1.8 pecl/phar/tests/phar_commitwrite.phpt:1.9 --- pecl/phar/tests/phar_commitwrite.phpt:1.8 Fri Jan 18 05:42:15 2008 +++ pecl/phar/tests/phar_commitwrite.phpt Sat Jan 19 04:26:21 2008 @@ -29,10 +29,10 @@ __HALT_COMPILER(); ?> --EXPECT-- -string(4461) "<?php +string(4501) "<?php if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); -include 'phar://' . __FILE__ . '/index.php'; +include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } class Extract_Phar @@ -42,6 +42,7 @@ const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; +const START = 'index.php'; static function go($D) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); @@ -106,7 +107,7 @@ self::$tmp[] = realpath($temp . '/' . $path); } chdir($temp); -include 'index.php'; +include self::START; } static function tmpdir() @@ -205,7 +206,7 @@ chdir(self::$origdir); } } -Extract_Phar::go(4433); +Extract_Phar::go(4501); __HALT_COMPILER(); ?>" string(200) "<?php function __autoload($class) http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_create_in_cwd.phpt?r1=1.7&r2=1.8&diff_format=u Index: pecl/phar/tests/phar_create_in_cwd.phpt diff -u pecl/phar/tests/phar_create_in_cwd.phpt:1.7 pecl/phar/tests/phar_create_in_cwd.phpt:1.8 --- pecl/phar/tests/phar_create_in_cwd.phpt:1.7 Fri Jan 18 05:42:15 2008 +++ pecl/phar/tests/phar_create_in_cwd.phpt Sat Jan 19 04:26:21 2008 @@ -32,7 +32,7 @@ unlink(dirname(__FILE__) . '/brandnewphar.phar'); ?> --EXPECT-- -int(4461) +int(4501) string(200) "<?php function __autoload($class) { http://cvs.php.net/viewvc.cgi/pecl/phar/tests/phar_createdefaultstub.phpt?view=markup&rev=1.1 Index: pecl/phar/tests/phar_createdefaultstub.phpt +++ pecl/phar/tests/phar_createdefaultstub.phpt --TEST-- Phar: Phar::createDefaultStub() with and without arg --SKIPIF-- <?php if (!extension_loaded("phar")) die("skip"); ?> --FILE-- <?php try { var_dump(Phar::createDefaultStub()); var_dump(Phar::createDefaultStub('my/custom/thingy.php')); var_dump(strlen(Phar::createDefaultStub(str_repeat('a', 400)))); var_dump(Phar::createDefaultStub(str_repeat('a', 401))); } catch(Exception $e) { echo $e->getMessage() . "\n"; } ?> ===DONE=== --EXPECT-- string(4501) "<?php if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } class Extract_Phar { static $tmp = array(); static $origdir; const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'index.php'; static function go($D) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); $fp = fopen(__FILE__, 'rb'); fseek($fp, $D); $L = unpack('V', fread($fp, 4)); $m = ''; do { $read = 8192; if ($L[1] - strlen($m) < 8192) { $read = $L[1] - strlen($m); } $last = fread($fp, $read); $m .= $last; } while (strlen($last) && strlen($m) < $L[1]); if (strlen($m) < $L[1]) { die('ERROR: manifest length read was "' . strlen($m) .'" should be "' . $L[1] . '"'); } $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'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . ' for compressed .phars'); } } $temp = self::tmpdir(); if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); if (!file_exists($sessionpath) && !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; } $temp .= '/pharextract'; if (!file_exists($temp)) { @mkdir($temp); $temp = realpath($temp); self::$tmp[] = $temp; } self::$origdir = getcwd(); foreach ($info['m'] as $path => $file) { $a = !file_exists(dirname($temp . '/' . $path)); @mkdir(dirname($temp . '/' . $path), 0777, true); clearstatcache(); if ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path)); if ($path[strlen($path) - 1] == '/') { mkdir($temp . '/' . $path); } else { file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); } self::$tmp[] = realpath($temp . '/' . $path); } chdir($temp); 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')) { return $var; } if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { return $var; } return @getenv('SystemRoot') . ' emp'; } if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { return $var; } return realpath('/tmp'); } static function _unpack($m) { $info = unpack('V', substr($m, 0, 4)); // skip API version, phar flags, alias, metadata $l = unpack('V', substr($m, 10, 4)); $m = substr($m, 14 + $l[1]); $s = unpack('V', substr($m, 0, 4)); $o = 0; $start = 4 + $s[1]; $ret['c'] = 0; for ($i = 0; $i < $info[1]; $i++) { // length of the file name $len = unpack('V', substr($m, $start, 4)); $start += 4; // file name $savepath = substr($m, $start, $len[1]); $start += $len[1]; // retrieve manifest data: // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags // 5 = metadata length $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] & 0xffffffff); $ret['m'][$savepath][7] = $o; $o += $ret['m'][$savepath][2]; $start += 24 + $ret['m'][$savepath][5]; $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; } return $ret; } static function extractFile($path, $entry, $fp) { $data = ''; $c = $entry[2]; while ($c) { if ($c < 8192) { $data .= @fread($fp, $c); $c = 0; } else { $c -= 8192; $data .= @fread($fp, 8192); } } if ($entry[4] & self::GZ) { $data = gzinflate($data); } elseif ($entry[4] & self::BZ2) { $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { die("Not valid 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)"); } return $data; } static function _removeTmpFiles() { // for removal of temp files usort(self::$tmp, 'strnatcasecmp'); array_reverse(self::$tmp, 1); if (count(self::$tmp)) { foreach (self::$tmp as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); } } chdir(self::$origdir); } } Extract_Phar::go(4501); __HALT_COMPILER(); ?>" string(4512) "<?php if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { Phar::interceptFileFuncs(); include 'phar://' . __FILE__ . '/' . Extract_Phar::START; return; } class Extract_Phar { static $tmp = array(); static $origdir; const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'my/custom/thingy.php'; static function go($D) { register_shutdown_function(array('Extract_Phar', '_removeTmpFiles')); $fp = fopen(__FILE__, 'rb'); fseek($fp, $D); $L = unpack('V', fread($fp, 4)); $m = ''; do { $read = 8192; if ($L[1] - strlen($m) < 8192) { $read = $L[1] - strlen($m); } $last = fread($fp, $read); $m .= $last; } while (strlen($last) && strlen($m) < $L[1]); if (strlen($m) < $L[1]) { die('ERROR: manifest length read was "' . strlen($m) .'" should be "' . $L[1] . '"'); } $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'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { die('Error: bzip2 extension is not enabled - bzdecompress() function needed' . ' for compressed .phars'); } } $temp = self::tmpdir(); if (!$temp) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== FALSE) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); if (!file_exists($sessionpath) && !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; } $temp .= '/pharextract'; if (!file_exists($temp)) { @mkdir($temp); $temp = realpath($temp); self::$tmp[] = $temp; } self::$origdir = getcwd(); foreach ($info['m'] as $path => $file) { $a = !file_exists(dirname($temp . '/' . $path)); @mkdir(dirname($temp . '/' . $path), 0777, true); clearstatcache(); if ($a) self::$tmp[] = realpath(dirname($temp . '/' . $path)); if ($path[strlen($path) - 1] == '/') { mkdir($temp . '/' . $path); } else { file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); } self::$tmp[] = realpath($temp . '/' . $path); } chdir($temp); 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')) { return $var; } if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) { return $var; } return @getenv('SystemRoot') . ' emp'; } if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) { return $var; } return realpath('/tmp'); } static function _unpack($m) { $info = unpack('V', substr($m, 0, 4)); // skip API version, phar flags, alias, metadata $l = unpack('V', substr($m, 10, 4)); $m = substr($m, 14 + $l[1]); $s = unpack('V', substr($m, 0, 4)); $o = 0; $start = 4 + $s[1]; $ret['c'] = 0; for ($i = 0; $i < $info[1]; $i++) { // length of the file name $len = unpack('V', substr($m, $start, 4)); $start += 4; // file name $savepath = substr($m, $start, $len[1]); $start += $len[1]; // retrieve manifest data: // 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags // 5 = metadata length $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] & 0xffffffff); $ret['m'][$savepath][7] = $o; $o += $ret['m'][$savepath][2]; $start += 24 + $ret['m'][$savepath][5]; $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; } return $ret; } static function extractFile($path, $entry, $fp) { $data = ''; $c = $entry[2]; while ($c) { if ($c < 8192) { $data .= @fread($fp, $c); $c = 0; } else { $c -= 8192; $data .= @fread($fp, 8192); } } if ($entry[4] & self::GZ) { $data = gzinflate($data); } elseif ($entry[4] & self::BZ2) { $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { die("Not valid 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)"); } return $data; } static function _removeTmpFiles() { // for removal of temp files usort(self::$tmp, 'strnatcasecmp'); array_reverse(self::$tmp, 1); if (count(self::$tmp)) { foreach (self::$tmp as $f) { if (file_exists($f)) is_dir($f) ? @rmdir($f) : @unlink($f); } } chdir(self::$origdir); } } Extract_Phar::go(4512); __HALT_COMPILER(); ?>" int(4892) Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed ===DONE===
« previous php.pecl.cvs (#9562) next »