]> granicus.if.org Git - php/commitdiff
bump API version if the created phar has directories in it, so that it won't load...
authorGreg Beaver <cellog@php.net>
Sat, 19 Jan 2008 18:30:30 +0000 (18:30 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 19 Jan 2008 18:30:30 +0000 (18:30 +0000)
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/tests/001.phpt
ext/phar/tests/033.phpt
ext/phar/tests/phar_test.inc

index 09cedbfdc220b8fdbba4e2a31567b6c5420f18e2..5f7d80c64feee030e88aa33fb86c14ba61304b48 100644 (file)
@@ -1331,7 +1331,7 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int
                if (buffer + entry.filename_len + 20 > endbuffer) {
                        MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)");
                }
-               if (buffer[entry.filename_len - 1] == '/') {
+               if ((manifest_ver & PHAR_API_VER_MASK) >= PHAR_API_MIN_DIR && buffer[entry.filename_len - 1] == '/') {
                        entry.is_dir = 1;
                        entry.filename_len--;
                        entry.flags |= PHAR_ENT_PERM_DEF_DIR;
@@ -2380,7 +2380,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error
        char *newstub;
        phar_entry_info *entry, *newentry;
        int halt_offset, restore_alias_len, global_flags = 0, closeoldfile;
-       char *buf, *pos;
+       char *buf, *pos, has_dirs = 0;
        char manifest[18], entry_buffer[24];
        off_t manifest_ftell;
        long offset;
@@ -2561,6 +2561,10 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error
                /* after excluding deleted files, calculate manifest size in bytes and number of entries */
                ++new_manifest_count;
 
+               if (entry->is_dir) {
+                       /* we use this to calculate API version, 1.1.1 is used for phars with directories */
+                       has_dirs = 1;
+               }
                if (entry->metadata) {
                        if (entry->metadata_str.c) {
                                smart_str_free(&entry->metadata_str);
@@ -2701,8 +2705,13 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error
        manifest_len = offset + phar->alias_len + sizeof(manifest) + main_metadata_str.len;
        phar_set_32(manifest, manifest_len);
        phar_set_32(manifest+4, new_manifest_count);
-       *(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF);
-       *(manifest + 9) = (unsigned char) (((PHAR_API_VERSION) & 0xF0));
+       if (has_dirs) {
+               *(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF);
+               *(manifest + 9) = (unsigned char) (((PHAR_API_VERSION) & 0xF0));
+       } else {
+               *(manifest + 8) = (unsigned char) (((PHAR_API_VERSION_NODIR) >> 8) & 0xFF);
+               *(manifest + 9) = (unsigned char) (((PHAR_API_VERSION_NODIR) & 0xF0));
+       }
        phar_set_32(manifest+10, global_flags);
        phar_set_32(manifest+14, phar->alias_len);
 
index f63a104f4283e6391032cf12dd13faab3232327c..6779dcc9c3332fcb4dd969cd34b26a78ff3a83c8 100755 (executable)
 #endif
 
 #define PHAR_EXT_VERSION_STR      "1.3.0"
-#define PHAR_API_VERSION_STR      "1.1.0"
+#define PHAR_API_VERSION_STR      "1.1.1"
 /* x.y.z maps to 0xyz0 */
-#define PHAR_API_VERSION          0x1100
+#define PHAR_API_VERSION          0x1110
+/* if we bump PHAR_API_VERSION, change this from 0x1100 to PHAR_API_VERSION */
+#define PHAR_API_VERSION_NODIR    0x1100
+#define PHAR_API_MIN_DIR          0x1110
 #define PHAR_API_MIN_READ         0x1000
 #define PHAR_API_MAJORVERSION     0x1000
 #define PHAR_API_MAJORVER_MASK    0xF000
index 42d3bd83c3bf5e1b93385a673cd994b13982f829..1205e4e1aaf79e02502afc48ef612bc63d2e9c60 100644 (file)
@@ -8,5 +8,5 @@ var_dump(Phar::apiVersion());
 ?>
 ===DONE===
 --EXPECT--
-string(5) "1.1.0"
+string(5) "1.1.1"
 ===DONE===
index 4866e9978df5fd86c78f7a977a2926a976fb9de5..9620fdaaa3aecea7b7f5b450390569255f64920c 100644 (file)
@@ -14,6 +14,7 @@ $file = '<?php include "' . $pname . '/a.php"; __HALT_COMPILER(); ?>';
 $files = array();
 $files['a.php']   = '<?php echo "This is a\n"; include "'.$pname.'/b.php"; ?>';
 $files['dir/'] = '';
+$hasdir = 1;
 include 'phar_test.inc';
 $a = new Phar($fname);
 var_dump($a['a.php']->isExecutable());
index 3ff5103e33cd5133eae6affb32a9228a49b9385a..7c4e9707b9e9264bf76d5e4a38658abce83789cb 100755 (executable)
@@ -51,7 +51,7 @@ foreach($files as $name => $cont)
 $alias = 'hio';
 
 if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
-$manifest = pack('VnVV', count($files), 0x1000, $gflags, strlen($alias)) . $alias . pack('V', strlen($pmeta)) . $pmeta . $manifest;
+$manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . $alias . pack('V', strlen($pmeta)) . $pmeta . $manifest;
 $file .= pack('V', strlen($manifest)) . $manifest;
 
 foreach($files as $cont)