]> granicus.if.org Git - php/commitdiff
- MFH
authorSteph Fox <sfox@php.net>
Wed, 14 May 2008 21:29:51 +0000 (21:29 +0000)
committerSteph Fox <sfox@php.net>
Wed, 14 May 2008 21:29:51 +0000 (21:29 +0000)
- Make internal code forward-compatible. This included a binary cast in the default stub, hence test updates.

18 files changed:
ext/phar/dirstream.c
ext/phar/func_interceptors.c
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c
ext/phar/shortarc.php
ext/phar/stream.c
ext/phar/stub.h
ext/phar/tests/files/phar_test.inc
ext/phar/tests/phar_commitwrite.phpt
ext/phar/tests/phar_convert_repeated.phpt
ext/phar/tests/phar_create_in_cwd.phpt
ext/phar/tests/phar_createdefaultstub.phpt
ext/phar/tests/phar_setdefaultstub.phpt
ext/phar/tests/tar/phar_convert_phar.phpt
ext/phar/tests/tar/phar_convert_phar2.phpt
ext/phar/tests/zip/phar_convert_phar.phpt
ext/phar/util.c

index 11088ead5b776ca3706cbc0d2b65876e22e5aad7..c1e8f316618ca3e00892377a7df505d1bc2c6ee8 100644 (file)
@@ -94,7 +94,8 @@ static size_t phar_dir_read(php_stream *stream, char *buf, size_t count TSRMLS_D
 {
        size_t to_read;
        HashTable *data = (HashTable *)stream->abstract;
-       char *key;
+       phar_zstr key;
+       char *str_key;
        uint keylen;
        ulong unused;
 
@@ -104,13 +105,14 @@ static size_t phar_dir_read(php_stream *stream, char *buf, size_t count TSRMLS_D
        if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(data, &key, &keylen, &unused, 0, NULL)) {
                return 0;
        }
+       PHAR_STR(key, str_key);
        zend_hash_move_forward(data);
        to_read = MIN(keylen, count);
        if (to_read == 0 || count < keylen) {
                return 0;
        }
        memset(buf, 0, sizeof(php_stream_dirent));
-       memcpy(((php_stream_dirent *) buf)->d_name, key, to_read);
+       memcpy(((php_stream_dirent *) buf)->d_name, str_key, to_read);
        ((php_stream_dirent *) buf)->d_name[to_read + 1] = '\0';
 
        return sizeof(php_stream_dirent);
@@ -186,10 +188,11 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
 {
        HashTable *data;
        int dirlen = strlen(dir);
-       char *save, *found, *key;
+       phar_zstr key;
+       char *entry, *found, *save, *str_key;
        uint keylen;
        ulong unused;
-       char *entry;
+
        ALLOC_HASHTABLE(data);
        zend_hash_init(data, 64, zend_get_hash_value, NULL, 0);
 
@@ -203,8 +206,9 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
                if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
                        break;
                }
+               PHAR_STR(key, str_key);
                if (keylen <= (uint)dirlen) {
-                       if (keylen < (uint)dirlen || !strncmp(key, dir, dirlen)) {
+                       if (keylen < (uint)dirlen || !strncmp(str_key, dir, dirlen)) {
                                if (SUCCESS != zend_hash_move_forward(manifest)) {
                                        break;
                                }
@@ -213,27 +217,27 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
                }
                if (*dir == '/') {
                        /* root directory */
-                       if (NULL != (found = (char *) memchr(key, '/', keylen))) {
+                       if (NULL != (found = (char *) memchr(str_key, '/', keylen))) {
                                /* the entry has a path separator and is a subdirectory */
-                               entry = (char *) safe_emalloc(found - key, 1, 1);
-                               memcpy(entry, key, found - key);
-                               keylen = found - key;
+                               entry = (char *) safe_emalloc(found - str_key, 1, 1);
+                               memcpy(entry, str_key, found - str_key);
+                               keylen = found - str_key;
                                entry[keylen] = '\0';
                        } else {
                                entry = (char *) safe_emalloc(keylen, 1, 1);
-                               memcpy(entry, key, keylen);
+                               memcpy(entry, str_key, keylen);
                                entry[keylen] = '\0';
                        }
                        goto PHAR_ADD_ENTRY;
                } else {
-                       if (0 != memcmp(key, dir, dirlen)) {
+                       if (0 != memcmp(str_key, dir, dirlen)) {
                                /* entry in directory not found */
                                if (SUCCESS != zend_hash_move_forward(manifest)) {
                                        break;
                                }
                                continue;
                        } else {
-                               if (key[dirlen] != '/') {
+                               if (str_key[dirlen] != '/') {
                                        if (SUCCESS != zend_hash_move_forward(manifest)) {
                                                break;
                                        }
@@ -241,7 +245,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
                                }
                        }
                }
-               save = key;
+               save = str_key;
                save += dirlen + 1; /* seek to just past the path separator */
                if (NULL != (found = (char *) memchr(save, '/', keylen - dirlen - 1))) {
                        /* is subdirectory */
@@ -289,7 +293,8 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char
 {
        php_url *resource = NULL;
        php_stream *ret;
-       char *internal_file, *key, *error;
+       char *internal_file, *error, *str_key;
+       phar_zstr key;
        uint keylen;
        ulong unused;
        phar_archive_data *phar;
@@ -367,7 +372,8 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char
                        if (HASH_KEY_NON_EXISTANT != 
                                        zend_hash_get_current_key_ex(
                                                &phar->manifest, &key, &keylen, &unused, 0, NULL)) {
-                               if (keylen > (uint)i_len && 0 == memcmp(key, internal_file, i_len)) {
+                               PHAR_STR(key, str_key);
+                               if (keylen > (uint)i_len && 0 == memcmp(str_key, internal_file, i_len)) {
                                        /* directory found */
                                        internal_file = estrndup(internal_file,
                                                        i_len);
index b92d61a4224bd874a6ca9463c45b4811eb4a58cc..853cf1477d01b482b27875782eb9d5bb1d56a9b5 100644 (file)
@@ -655,7 +655,8 @@ notfound:
                                        goto stat_entry;
                                } else {
                                        phar_archive_data *phar = *pphar;
-                                       char *key;
+                                       phar_zstr key;
+                                       char *str_key;
                                        uint keylen;
                                        ulong unused;
 
@@ -667,11 +668,12 @@ notfound:
                                                if (HASH_KEY_NON_EXISTANT !=
                                                                zend_hash_get_current_key_ex(
                                                                        &phar->manifest, &key, &keylen, &unused, 0, NULL)) {
-                                                       if (!memcmp(actual, key, actual_len)) {
+                                                       PHAR_STR(key, str_key);
+                                                       if (!memcmp(actual, str_key, actual_len)) {
                                                                efree(save2);
                                                                efree(entry);
                                                                /* directory found, all dirs have the same stat */
-                                                               if (key[actual_len] == '/') {
+                                                               if (str_key[actual_len] == '/') {
                                                                        sb.st_size = 0;
                                                                        sb.st_mode = 0777;
                                                                        sb.st_mode |= S_IFDIR; /* regular directory */
index 4e14d2bbb606ffecc11e8aba8ddf9cbc9132c8fa..2ac7209f1c3a5f7c2038966c8dbaea6f19ade0eb 100644 (file)
@@ -817,7 +817,7 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int
                register_alias = 1;
                temp_alias = 1;
        }
-       
+
        /* we have 5 32-bit items plus 1 byte at least */
        if (manifest_count > ((manifest_len - 10 - tmp_len) / (5 * 4 + 1))) {
                /* prevent serious memory issues */
@@ -1592,7 +1592,8 @@ woohoo:
                                return FAILURE;
                        }
                } else {
-                       char *key;
+                       phar_zstr key;
+                       char *str_key;
                        uint keylen;
                        ulong unused;
 
@@ -1602,11 +1603,13 @@ woohoo:
                                        break;
                                }
 
+                               PHAR_STR(key, str_key);
+
                                if (keylen > (uint) filename_len) {
                                        zend_hash_move_forward(&(PHAR_GLOBALS->phar_fname_map));
                                        continue;
                                }
-                               if (!memcmp(filename, key, keylen) && ((uint)filename_len == keylen
+                               if (!memcmp(filename, str_key, keylen) && ((uint)filename_len == keylen
                                        || filename[keylen] == '/' || filename[keylen] == '\0')) {
                                        if (FAILURE == zend_hash_get_current_data(&(PHAR_GLOBALS->phar_fname_map), (void **) &pphar)) {
                                                break;
@@ -2847,7 +2850,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type
                                }
                        } else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) {
                                /* compressed phar */
-#if PHP_VERSION_ID >= 50300 && PHP_VERSION_ID < 60000
+#if PHP_VERSION_ID >= 50300
                                file_handle->type = ZEND_HANDLE_STREAM;
                                file_handle->free_filename = 0;
                                file_handle->handle.stream.handle  = phar;
index 1aa54251250e5d7dab76d83d9450ca4cab3e9eba..cec12ead319b10f45f11bfe5c2b05092039bcbdf 100755 (executable)
@@ -354,8 +354,17 @@ extern char *(*phar_save_resolve_path)(const char *filename, int filename_len TS
 # endif
 #endif
 
-BEGIN_EXTERN_C()
+#if PHP_VERSION_ID >= 60000
+typedef zstr phar_zstr;
+#define PHAR_STR(a, b) \
+       spprintf(&b, 0, "%r", a.s);
+#else
+typedef char *phar_zstr;
+#define PHAR_STR(a, b) \
+       b = a;
+#endif
 
+BEGIN_EXTERN_C()
 
 #ifdef PHP_WIN32
 char *tsrm_strtok_r(char *s, const char *delim, char **last);
index 98b602adbc8b986a30f15b94f919bec1754d974d..1e37e5d8c464a1cb25ee5008e12c7b3d0bc9ab86 100755 (executable)
@@ -778,7 +778,7 @@ PHP_METHOD(Phar, webPhar)
                        mime.len = Z_STRLEN_PP(val); \
                } \
                mime.type = ret; \
-               zend_hash_update(&mimetypes, key, keylen-1, (void *)&mime, sizeof(phar_mime_type), NULL);
+               zend_hash_update(&mimetypes, str_key, keylen-1, (void *)&mime, sizeof(phar_mime_type), NULL);
 
        if (mimeoverride) {
                if (!zend_hash_num_elements(Z_ARRVAL_P(mimeoverride))) {
@@ -786,9 +786,11 @@ PHP_METHOD(Phar, webPhar)
                }
                for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(mimeoverride)); SUCCESS == zend_hash_has_more_elements(Z_ARRVAL_P(mimeoverride)); zend_hash_move_forward(Z_ARRVAL_P(mimeoverride))) {
                        zval **val;
-                       char *key;
+                       phar_zstr key;
+                       char *str_key;
                        uint keylen;
                        ulong intkey;
+
                        if (HASH_KEY_IS_LONG == zend_hash_get_current_key_ex(Z_ARRVAL_P(mimeoverride), &key, &keylen, &intkey, 0, NULL)) {
                                zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Key of MIME type overrides array must be a file extension, was \"%d\"", intkey);
                                phar_entry_delref(phar TSRMLS_CC);
@@ -797,8 +799,11 @@ PHP_METHOD(Phar, webPhar)
 #endif
                                RETURN_FALSE;
                        }
+
+                       PHAR_STR(key, str_key);
+
                        if (FAILURE == zend_hash_get_current_data(Z_ARRVAL_P(mimeoverride), (void **) &val)) {
-                               zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Failed to retrieve Mime type for extension \"%s\"", key);
+                               zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Failed to retrieve Mime type for extension \"%s\"", str_key);
                                phar_entry_delref(phar TSRMLS_CC);
 #ifdef PHP_WIN32
                                efree(fname);
@@ -1114,11 +1119,8 @@ PHP_METHOD(Phar, __construct)
                return;
        }
 
-#if PHP_VERSION_ID >= 60000
-       objname = phar_obj->std.ce->name.s;
-#else
-       objname = phar_obj->std.ce->name;
-#endif
+       PHAR_STR(phar_obj->std.ce->name, objname);
+
        if (!strncmp(objname, "PharData", 8)) {
                is_data = 1;
        } else {
@@ -1315,7 +1317,9 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{
        phar_entry_data *data;
        php_stream *fp;
        long contents_len;
-       char *fname, *error, *str_key, *base = p_obj->b, *opened, *save = NULL, *temp = NULL;
+       char *fname, *error, *base = p_obj->b, *opened, *save = NULL, *temp = NULL;
+       phar_zstr key;
+       char *str_key;
        zend_class_entry *ce = p_obj->c;
        phar_archive_object *phar_obj = p_obj->p;
        char *str = "[stream]";
@@ -1339,10 +1343,14 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{
                                return ZEND_HASH_APPLY_STOP;
                        }
                        if (iter->funcs->get_current_key) {
-                               key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC);
+                               key_type = iter->funcs->get_current_key(iter, &key, &str_key_len, &int_key TSRMLS_CC);
+
                                if (EG(exception)) {
                                        return ZEND_HASH_APPLY_STOP;
                                }
+
+                               PHAR_STR(key, str_key);
+
                                if (key_type == HASH_KEY_IS_LONG) {
                                        zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
                                        return ZEND_HASH_APPLY_STOP;
@@ -1438,10 +1446,14 @@ phar_spl_fileinfo:
                }
        } else {
                if (iter->funcs->get_current_key) {
-                       key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC);
+                       key_type = iter->funcs->get_current_key(iter, &key, &str_key_len, &int_key TSRMLS_CC);
+
                        if (EG(exception)) {
                                return ZEND_HASH_APPLY_STOP;
                        }
+
+                       PHAR_STR(key, str_key);
+
                        if (key_type == HASH_KEY_IS_LONG) {
                                zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Iterator %s returned an invalid key (must return a string)", ce->name);
                                return ZEND_HASH_APPLY_STOP;
index fa5263664664acac7a98f5956e78459b756ecc2d..748afeda2e2e40bb865e4ebbf519238f4426f0d4 100644 (file)
@@ -268,7 +268,7 @@ class Extract_Phar
                 $stat[7] . ")");
         }
 
-        if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+        if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
             die("Invalid internal .phar file (checksum error)");
         }
 
index 3d9f14e4d45f67f6c98d2ee26818877b0f784219..e6c57a89ab763c6a9e9e8d8d19d73a1b2b3f7ff0 100644 (file)
@@ -501,7 +501,8 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
                                  php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) /* {{{ */
 {
        php_url *resource = NULL;
-       char *internal_file, *key, *error;
+       phar_zstr key;
+       char *internal_file, *error, *str_key;
        uint keylen;
        ulong unused;
        phar_archive_data *phar;
@@ -562,9 +563,10 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
                        if (HASH_KEY_NON_EXISTANT !=
                                        zend_hash_get_current_key_ex(
                                                &phar->manifest, &key, &keylen, &unused, 0, NULL)) {
-                               if (keylen >= (uint)internal_file_len && 0 == memcmp(internal_file, key, internal_file_len)) {
+                               PHAR_STR(key, str_key);
+                               if (keylen >= (uint)internal_file_len && 0 == memcmp(internal_file, str_key, internal_file_len)) {
                                        /* directory found, all dirs have the same stat */
-                                       if (key[internal_file_len] == '/') {
+                                       if (str_key[internal_file_len] == '/') {
                                                phar_dostat(phar, NULL, ssb, 1, phar->alias, phar->alias_len TSRMLS_CC);
                                                php_url_free(resource);
                                                return SUCCESS;
@@ -577,7 +579,8 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
                }
                /* check for mounted directories */
                if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
-                       char *key;
+                       phar_zstr key;
+                       char *str_key;
                        ulong unused;
                        uint keylen;
        
@@ -586,7 +589,8 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
                                if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
                                        break;
                                }
-                               if ((int)keylen >= internal_file_len || strncmp(key, internal_file, keylen)) {
+                               PHAR_STR(key, str_key);
+                               if ((int)keylen >= internal_file_len || strncmp(str_key, internal_file, keylen)) {
                                        continue;
                                } else {
                                        char *test;
@@ -594,7 +598,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, char *url, int flags,
                                        phar_entry_info *entry;
                                        php_stream_statbuf ssbi;
        
-                                       if (SUCCESS != zend_hash_find(&phar->manifest, key, keylen, (void **) &entry)) {
+                                       if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) {
                                                goto free_resource;
                                        }
                                        if (!entry->tmp || !entry->is_mounted) {
index f5858e2f07cc9825bc54bf17a0a9c83d238745ec..104a8baa639e85dca23c109de623d28d502cc358 100644 (file)
@@ -25,9 +25,9 @@ static inline void phar_get_stub(const char *index_php, const char *web, size_t
        static const char newstub1_1[] = "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, \" 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) {\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\nclass Extract_Phar\n{\nstatic $temp;\nstatic $origdir;\nconst GZ = 0x1000;\nconst BZ2 = 0x2000;\nconst MASK = 0x3000;\nconst START = '";
        static const char newstub2[] = "';\nconst LEN = ";
        static const char newstub3_0[] = ";\n\nstatic function go($return = false)\n{\n$fp = fopen(__FILE__, 'rb');\nfseek($fp, self::LEN);\n$L = unpack('V', $a = fread($fp, 4));\n$m = '';\n\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]);\n\nif (strlen($m) < $L[1]) {\ndie('ERROR: manifest length read was \"' .\nstrlen($m) .'\" should be \"' .\n$L[1] . '\"');\n}\n\n$info = self::_unpack($m);\n$f = $info['c'];\n\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}\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\n$temp = self::tmpdir();\n\nif (!$temp || !is_writable($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\n$temp .= '/pharextract/'.basename(__FILE__, '.phar');\nself::$temp = $temp;\nself::$origdir = getcwd();\n@mkdir($temp, 0777, true);\n$temp = realpath($temp);\n\nif (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {\nself::_removeTmpFiles($temp, getcwd());\n@mkdir($temp, 0777, true);\n@file_put_contents($temp . '/' . md5_file(__FILE__), '');\n\nforeach ($info['m'] as $path => $file) {\n$a = !file_exists(dirname($temp . '/' . $path));\n@mkdir(dirname($temp . '/' . $path), 0777, true);\nclearstatcache();\n\nif ($path[strlen($path) - 1] == '/') {\n@mkdir($temp . '/' . $path, 0777);\n} else {\nfile_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));\n@chmod($temp . '/' . $path, 0666);\n}\n}\n}\n\nchdir($temp);\n\nif (!$return) {\ninclude self::START;\n}\n}\n\nstatic fun";
-       static const char newstub3_1[] = "ction 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 $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;\n\nfor ($i = 0; $i < $info[1]; $i++) {\n $len = unpack('V', substr($m, $start, 4));\n$start += 4;\n $savepath = substr($m, $start, $len[1]);\n$start += $len[1];\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];\n\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}\n\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\n\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\n\nif ($entry[3] != sprintf(\"%u\", crc32($data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\n\nreturn $data;\n}\n\nstatic function _removeTmpFiles($temp, $origdir)\n{\nchdir($temp);\n\nforeach (glob('*') as $f) {\nif (file_exists($f)) {\nis_dir($f) ? @rmdir($f) : @unlink($f);\nif (file_exists($f) && is_dir($f)) {\nself::_removeTmpFiles($f, getcwd());\n}\n}\n}\n\n@rmdir($temp);\nclearstatcache();\nchdir($origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>";
+       static const char newstub3_1[] = "ction 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 $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;\n\nfor ($i = 0; $i < $info[1]; $i++) {\n $len = unpack('V', substr($m, $start, 4));\n$start += 4;\n $savepath = substr($m, $start, $len[1]);\n$start += $len[1];\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];\n\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}\n\nif ($entry[4] & self::GZ) {\n$data = gzinflate($data);\n} elseif ($entry[4] & self::BZ2) {\n$data = bzdecompress($data);\n}\n\nif (strlen($data) != $entry[0]) {\ndie(\"Invalid internal .phar file (size error \" . strlen($data) . \" != \" .\n$stat[7] . \")\");\n}\n\nif ($entry[3] != sprintf(\"%u\", crc32((binary)$data) & 0xffffffff)) {\ndie(\"Invalid internal .phar file (checksum error)\");\n}\n\nreturn $data;\n}\n\nstatic function _removeTmpFiles($temp, $origdir)\n{\nchdir($temp);\n\nforeach (glob('*') as $f) {\nif (file_exists($f)) {\nis_dir($f) ? @rmdir($f) : @unlink($f);\nif (file_exists($f) && is_dir($f)) {\nself::_removeTmpFiles($f, getcwd());\n}\n}\n}\n\n@rmdir($temp);\nclearstatcache();\nchdir($origdir);\n}\n}\n\nExtract_Phar::go();\n__HALT_COMPILER(); ?>";
 
-       static const int newstub_len = 6633;
+       static const int newstub_len = 6641;
 
        *len = spprintf(stub, name_len + web_len + newstub_len, "%s%s%s%s%s%s%d%s%s", newstub0, web, newstub1_0, newstub1_1, index_php, newstub2, name_len + web_len + newstub_len, newstub3_0, newstub3_1);
 }
index a5e9d3fdc8ac8859624885c6df19c694f5dbf187..0f989f9db11238c0cf01a1a402780c9001136e29 100644 (file)
@@ -36,7 +36,7 @@ foreach($files as $name => $cont)
        if (empty($comp)) $comp = $cont;
        if (empty($ulen)) $ulen = strlen($cont);
        if (empty($clen)) $clen = strlen($comp);
-       if (empty($crc32))$crc32= crc32($cont);
+       if (empty($crc32))$crc32= crc32((binary)$cont);
        if (isset($meta)) $meta = serialize($meta);
 
        // write manifest entry
index 63878355b04b401eb3dbc28cb16201f958b0dd57..447d1e8309e4c3294ae09418fb05216524a785f2 100644 (file)
@@ -29,7 +29,7 @@ unlink(dirname(__FILE__) . '/brandnewphar.phar');
 __HALT_COMPILER();
 ?>
 --EXPECT--
-int(6651)
+int(6659)
 string(200) "<?php
 function __autoload($class)
 {
index b2ef195ea7868673585afc07f12d937af0795612..fe0888ebbf2b0bff6ab9479c11da89128c18574b 100644 (file)
@@ -123,7 +123,7 @@ NULL
 bool(true)
 bool(false)
 bool(false)
-int(6651)
+int(6659)
 NULL
 ================= convertToZip() =====================
 bool(false)
index 83de7bed289833967a25e4e3daa0e4febe64ee2e..c4f74b6d6ca8590f4f31141b543c0b8e957b41b9 100644 (file)
@@ -32,7 +32,7 @@ __HALT_COMPILER();
 unlink(dirname(__FILE__) . '/brandnewphar.phar');
 ?>
 --EXPECT--
-int(6651)
+int(6659)
 string(200) "<?php
 function __autoload($class)
 {
index a8648dc311a3258ceeeb7f798a49e2e059ca1b1f..642aac9accb505ce3ac49b2ce32aac295b94ff2e 100644 (file)
@@ -34,7 +34,7 @@ echo $e->getMessage() . "\n";
 ?>
 ===DONE===
 --EXPECT--
-string(6651) "<?php
+string(6659) "<?php
 
 $web = 'index.php';
 
@@ -144,7 +144,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'index.php';
-const LEN = 6653;
+const LEN = 6661;
 
 static function go($return = false)
 {
@@ -298,7 +298,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -328,7 +328,7 @@ Extract_Phar::go();
 __HALT_COMPILER(); ?>"
 ============================================================================
 ============================================================================
-string(6662) "<?php
+string(6670) "<?php
 
 $web = 'index.php';
 
@@ -438,7 +438,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'my/custom/thingy.php';
-const LEN = 6664;
+const LEN = 6672;
 
 static function go($return = false)
 {
@@ -592,7 +592,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -622,7 +622,7 @@ Extract_Phar::go();
 __HALT_COMPILER(); ?>"
 ============================================================================
 ============================================================================
-int(7042)
+int(7050)
 ============================================================================
 ============================================================================
 Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
@@ -630,7 +630,7 @@ Illegal filename passed in for stub creation, was 401 characters long, and only
 ============================================================================
 ============================================================================
 ============================================================================
-string(6664) "<?php
+string(6672) "<?php
 
 $web = 'the/web.php';
 
@@ -740,7 +740,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'my/custom/thingy.php';
-const LEN = 6666;
+const LEN = 6674;
 
 static function go($return = false)
 {
@@ -894,7 +894,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -924,6 +924,6 @@ Extract_Phar::go();
 __HALT_COMPILER(); ?>"
 ============================================================================
 ============================================================================
-int(7042)
+int(7050)
 Illegal web filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
 ===DONE===
index a36c005eac3e1155ed25b1a217f9668e78559707..e907ca1236154dbb73376c75ed47e8cfb428e090 100644 (file)
@@ -54,7 +54,7 @@ try {
 unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
 ?>
 --EXPECT--
-string(6653) "<?php
+string(6661) "<?php
 
 $web = 'index.php';
 
@@ -164,7 +164,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'index.php';
-const LEN = 6653;
+const LEN = 6661;
 
 static function go($return = false)
 {
@@ -318,7 +318,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -349,7 +349,7 @@ __HALT_COMPILER(); ?>
 "
 ============================================================================
 ============================================================================
-string(6664) "<?php
+string(6672) "<?php
 
 $web = 'index.php';
 
@@ -459,7 +459,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'my/custom/thingy.php';
-const LEN = 6664;
+const LEN = 6672;
 
 static function go($return = false)
 {
@@ -613,7 +613,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -644,7 +644,7 @@ __HALT_COMPILER(); ?>
 "
 ============================================================================
 ============================================================================
-string(6666) "<?php
+string(6674) "<?php
 
 $web = 'the/web.php';
 
@@ -754,7 +754,7 @@ const GZ = 0x1000;
 const BZ2 = 0x2000;
 const MASK = 0x3000;
 const START = 'my/custom/thingy.php';
-const LEN = 6666;
+const LEN = 6674;
 
 static function go($return = false)
 {
@@ -908,7 +908,7 @@ die("Invalid internal .phar file (size error " . strlen($data) . " != " .
 $stat[7] . ")");
 }
 
-if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) {
+if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
 die("Invalid internal .phar file (checksum error)");
 }
 
@@ -939,6 +939,6 @@ __HALT_COMPILER(); ?>
 "
 ============================================================================
 ============================================================================
-int(7044)
+int(7052)
 Illegal filename passed in for stub creation, was 401 characters long, and only 400 or less is allowed
 ===DONE===
index 6a7d78ea8bf1570b63e515ebb86a0b1d5e602a89..7ce221991b8e8fa37167569d89b528747896e451 100644 (file)
@@ -47,12 +47,12 @@ __HALT_COMPILER();
 ?>
 --EXPECT--
 bool(false)
-int(6651)
+int(6659)
 bool(true)
 string(60) "<?php // tar-based phar archive stub file
 __HALT_COMPILER();"
 bool(true)
-int(6651)
+int(6659)
 bool(true)
-int(6651)
+int(6659)
 ===DONE===
index 496948b14c34a49cbf8b14ff6398864224821e69..03a6429d2aae2e40d9b78f87da0a6921dff6f2fc 100644 (file)
@@ -49,14 +49,14 @@ __HALT_COMPILER();
 ?>
 --EXPECT--
 bool(false)
-int(6651)
+int(6659)
 bool(true)
 string(60) "<?php // tar-based phar archive stub file
 __HALT_COMPILER();"
 bool(true)
 int(4096)
-int(6651)
+int(6659)
 bool(true)
 bool(true)
-int(6651)
+int(6659)
 ===DONE===
index 815656dbf671d509ac02a79a8bba81fc9d71c7cc..d511a0b36ac78d9eeb000d202756dd2fbdd1039e 100644 (file)
@@ -46,12 +46,12 @@ __HALT_COMPILER();
 ?>
 --EXPECT--
 bool(false)
-int(6651)
+int(6659)
 bool(true)
 string(60) "<?php // zip-based phar archive stub file
 __HALT_COMPILER();"
 bool(true)
-int(6651)
+int(6659)
 bool(true)
-int(6651)
+int(6659)
 ===DONE===
index 77e83098a42cf14776c2fbdf7c6990e28a38f7af..93587d067859b8b613a9eca25b63b6b39f63573c 100644 (file)
@@ -1183,7 +1183,8 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
                }
                return entry;
        } else if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
-               char *key;
+               phar_zstr key;
+               char *str_key;
                ulong unused;
                uint keylen;
 
@@ -1192,7 +1193,10 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
                        if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
                                break;
                        }
-                       if ((int)keylen >= path_len || strncmp(key, path, keylen)) {
+
+                       PHAR_STR(key, str_key);
+
+                       if ((int)keylen >= path_len || strncmp(str_key, path, keylen)) {
                                continue;
                        } else {
                                char *test;
@@ -1200,15 +1204,15 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
                                phar_entry_info *entry;
                                php_stream_statbuf ssb;
 
-                               if (SUCCESS != zend_hash_find(&phar->manifest, key, keylen, (void **) &entry)) {
+                               if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) {
                                        if (error) {
-                                               spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", key);
+                                               spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", str_key);
                                        }
                                        return NULL;
                                }
                                if (!entry->tmp || !entry->is_mounted) {
                                        if (error) {
-                                               spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", key);
+                                               spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", str_key);
                                        }
                                        return NULL;
                                }
@@ -1254,7 +1258,8 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
        if (dir) {
                /* try to find a directory */
                HashTable *manifest;
-               char *key;
+               phar_zstr key;
+               char *str_key;
                uint keylen;
                ulong unused;
 
@@ -1267,14 +1272,17 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
                        if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
                                break;
                        }
-                       if (0 != memcmp(key, path, path_len)) {
+
+                       PHAR_STR(key, str_key);
+
+                       if (0 != memcmp(str_key, path, path_len)) {
                                /* entry in directory not found */
                                if (SUCCESS != zend_hash_move_forward(manifest)) {
                                        break;
                                }
                                continue;
                        } else {
-                               if (key[path_len] != '/') {
+                               if (str_key[path_len] != '/') {
                                        if (SUCCESS != zend_hash_move_forward(manifest)) {
                                                break;
                                        }