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;
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;
/* 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);
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);
#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
$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)