From: Greg Beaver Date: Sat, 19 Jan 2008 18:30:30 +0000 (+0000) Subject: bump API version if the created phar has directories in it, so that it won't load... X-Git-Tag: RELEASE_2_0_0a1~844 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5358c072537699f5bf6e55b96d2d7b4b4c1ab26;p=php bump API version if the created phar has directories in it, so that it won't load with older phar versions --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 09cedbfdc2..5f7d80c64f 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -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); diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index f63a104f42..6779dcc9c3 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -80,9 +80,12 @@ #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 diff --git a/ext/phar/tests/001.phpt b/ext/phar/tests/001.phpt index 42d3bd83c3..1205e4e1aa 100644 --- a/ext/phar/tests/001.phpt +++ b/ext/phar/tests/001.phpt @@ -8,5 +8,5 @@ var_dump(Phar::apiVersion()); ?> ===DONE=== --EXPECT-- -string(5) "1.1.0" +string(5) "1.1.1" ===DONE=== diff --git a/ext/phar/tests/033.phpt b/ext/phar/tests/033.phpt index 4866e9978d..9620fdaaa3 100644 --- a/ext/phar/tests/033.phpt +++ b/ext/phar/tests/033.phpt @@ -14,6 +14,7 @@ $file = ''; $files = array(); $files['a.php'] = ''; $files['dir/'] = ''; +$hasdir = 1; include 'phar_test.inc'; $a = new Phar($fname); var_dump($a['a.php']->isExecutable()); diff --git a/ext/phar/tests/phar_test.inc b/ext/phar/tests/phar_test.inc index 3ff5103e33..7c4e9707b9 100755 --- a/ext/phar/tests/phar_test.inc +++ b/ext/phar/tests/phar_test.inc @@ -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)