if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
+ if (keylen <= dirlen) {
+ if (keylen < dirlen || !strncmp(key, dir, dirlen)) {
+ if (SUCCESS != zend_hash_move_forward(manifest)) {
+ break;
+ }
+ continue;
+ }
+ }
if (*dir == '/') {
/* root directory */
if (NULL != (found = (char *) memchr(key, '/', keylen))) {
return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
} else {
efree(dir);
- FREE_HASHTABLE(data);
- return NULL;
+ return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
}
}
/* }}}*/
uint keylen;
ulong unused;
phar_archive_data *phar;
- phar_entry_info *entry;
+ phar_entry_info *entry = NULL;
uint host_len;
if ((resource = phar_open_url(wrapper, path, mode, options TSRMLS_CC)) == NULL) {
php_url_free(resource);
return NULL;
}
- if (SUCCESS == zend_hash_find(&phar->manifest, internal_file, strlen(internal_file), (void**)&entry)) {
+ if (SUCCESS == zend_hash_find(&phar->manifest, internal_file, strlen(internal_file), (void**)&entry) && !entry->is_dir) {
php_url_free(resource);
return NULL;
+ } else if (entry && entry->is_dir) {
+ internal_file = estrdup(internal_file);
+ php_url_free(resource);
+ return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
} else {
+ int i_len = strlen(internal_file);
+
/* search for directory */
zend_hash_internal_pointer_reset(&phar->manifest);
while (FAILURE != zend_hash_has_more_elements(&phar->manifest)) {
if (HASH_KEY_NON_EXISTANT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
- if (0 == memcmp(key, internal_file, strlen(internal_file))) {
+ if (keylen > i_len && 0 == memcmp(key, internal_file, i_len)) {
/* directory found */
internal_file = estrndup(internal_file,
- strlen(internal_file));
+ i_len);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
}
zval filterparams;
array_init(&filterparams);
+ /* ext/zlib zval_dtors a separated zval, so we have to make sure it doesn't destroy ours */
+#if PHP_VERSION_ID < 50300
+ filterparams->refcount = 26;
+#else
+ Z_SET_REFCOUNT(filterparams, 26);
+#endif
/* this is defined in zlib's zconf.h */
#ifndef MAX_WBITS
#define MAX_WBITS 15
#endif
add_assoc_long(&filterparams, "window", MAX_WBITS + 16);
filter = php_stream_filter_create("zlib.deflate", &filterparams, php_stream_is_persistent(phar->fp) TSRMLS_CC);
+ zval_dtor(&filterparams);
if (!filter) {
/* copy contents uncompressed rather than lose them */
php_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL);