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);
--- /dev/null
+--TEST--
+Phar: temporary manifest entry test
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+include "extfile.php";
+?>';
+$a->setStub('<?php
+include "phar://" . __FILE__ . "/index.php";
+__HALT_COMPILER();');
+unset($a);
+file_put_contents(dirname(__FILE__) . '/extfile.php', '<?php
+var_dump(__FILE__);
+?>');
+include dirname(__FILE__) . '/extfile.php';
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
+@unlink(dirname(__FILE__) . '/extfile.php');
+?>
+--EXPECTF--
+string(%d) "%sextfile.php"
+string(%d) "phar://%sextfile.php"
+===DONE===
\ No newline at end of file
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))) {
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) /* {{{ */
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;