From 9c62ef11242dc9ab795bb13d1152df24fdcb4662 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Mon, 18 Feb 2008 03:37:51 +0000 Subject: [PATCH] add externally parsed files to temporary manifest (this will be made optional and must be explicitly enabled per-phar) --- ext/phar/phar.c | 7 +++++++ ext/phar/tests/tempmanifest1.phpt | 34 +++++++++++++++++++++++++++++++ ext/phar/util.c | 22 +++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 ext/phar/tests/tempmanifest1.phpt diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 3904043fbc..d86856f9a9 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2567,12 +2567,19 @@ int phar_zend_open(const char *filename, zend_file_handle *handle TSRMLS_DC) /* if (SUCCESS == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) { if (!(entry = phar_find_in_include_path(entry, old, *pphar TSRMLS_CC))) { /* this file is not in the phar, use the original path */ + if (SUCCESS == phar_orig_zend_open(filename, handle TSRMLS_CC)) { + if (filename[0] != '.' && SUCCESS == phar_mount_entry(*pphar, handle->opened_path ? handle->opened_path : filename, strlen(handle->opened_path ? handle->opened_path : filename), filename, strlen(filename), 0)) { + entry = (char *) filename; + goto dopharthing; + } + } efree(old); efree(arch); goto skip_phar; } } } +dopharthing: efree(old); /* auto-convert to phar:// */ spprintf(&name, 4096, "phar://%s/%s", arch, entry); diff --git a/ext/phar/tests/tempmanifest1.phpt b/ext/phar/tests/tempmanifest1.phpt new file mode 100644 index 0000000000..bff1026b1c --- /dev/null +++ b/ext/phar/tests/tempmanifest1.phpt @@ -0,0 +1,34 @@ +--TEST-- +Phar: temporary manifest entry test +--SKIPIF-- + +--INI-- +phar.readonly=0 +--FILE-- +'; +$a->setStub(''); +include dirname(__FILE__) . '/extfile.php'; +include $fname; +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +string(%d) "%sextfile.php" +string(%d) "phar://%sextfile.php" +===DONE=== \ No newline at end of file diff --git a/ext/phar/util.c b/ext/phar/util.c index d01c8cd370..809835832e 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -78,6 +78,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len, int is_dir TSRMLS_DC) { phar_entry_info entry = {0}; + php_stream_statbuf ssb; #if PHP_MAJOR_VERSION < 6 if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_ALLOW_ONLY_FILE))) { @@ -98,7 +99,20 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, entry.is_crc_checked = 1; entry.fp_type = PHAR_TMP; entry.is_dir = is_dir; - return zend_hash_add(&phar->manifest, path, path_len, (void*)&entry, sizeof(phar_entry_info), NULL); + + if (SUCCESS != php_stream_stat_path(entry.link, &ssb)) { + efree(entry.link); + efree(entry.filename); + return FAILURE; + } + entry.uncompressed_filesize = entry.compressed_filesize = ssb.sb.st_size; + entry.flags = ssb.sb.st_mode; + if (SUCCESS == zend_hash_add(&phar->manifest, path, path_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + return SUCCESS; + } + efree(entry.link); + efree(entry.filename); + return FAILURE; } char *phar_find_in_include_path(char *file, char *entry, phar_archive_data *phar TSRMLS_DC) /* {{{ */ @@ -416,6 +430,12 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) char *filtername; off_t loc; + if (entry->fp_type == PHAR_TMP) { + if (!entry->fp) { + entry->fp = php_stream_open_wrapper(entry->link, "rb", STREAM_MUST_SEEK|0, NULL); + } + return SUCCESS; + } if (entry->fp_type != PHAR_FP) { /* either newly created or already modified */ return SUCCESS; -- 2.50.1