From: Greg Beaver Date: Fri, 5 Jan 2007 01:50:26 +0000 (+0000) Subject: fix creation of new files within an existing phar, add test X-Git-Tag: RELEASE_1_0_0RC1~399 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00f516cc99e107bc315172251c66ba562210f507;p=php fix creation of new files within an existing phar, add test --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index bbbf069090..912a5431ce 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -374,10 +374,11 @@ static phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len ret->internal_file->crc32 = 0; return ret; } - /* create an entry, this is a new file */ - if ((entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC)) != NULL) { - ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data)); - entry = (phar_entry_info *) emalloc(sizeof(phar_entry_info)); + /* create a new phar data holder */ + ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data)); + if ((entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC)) == NULL) { + /* create an entry, this is a new file */ + etemp.flags = 0; etemp.filename_len = path_len; etemp.filename = estrndup(path, path_len); etemp.uncompressed_filesize = 0; @@ -388,8 +389,9 @@ static phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len etemp.crc_checked = TRUE; etemp.fp = NULL; etemp.temp_file = 0; - memcpy((void *) entry, (void *) &etemp, sizeof(phar_entry_info)); - zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)entry, sizeof(phar_entry_info), NULL); + zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), NULL); + /* retrieve the phar manifest copy */ + entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC); } ret->phar = phar; ret->internal_file = entry; diff --git a/ext/phar/tests/open_for_write_existing.phpt b/ext/phar/tests/open_for_write_existing.phpt index 769f6e4640..81a7217bff 100644 --- a/ext/phar/tests/open_for_write_existing.phpt +++ b/ext/phar/tests/open_for_write_existing.phpt @@ -30,6 +30,7 @@ fwrite($fp, 'extra'); fclose($fp); include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; ?> + ===DONE=== --CLEAN-- diff --git a/ext/phar/tests/open_for_write_newfile.phpt b/ext/phar/tests/open_for_write_newfile.phpt new file mode 100644 index 0000000000..ed017d733c --- /dev/null +++ b/ext/phar/tests/open_for_write_newfile.phpt @@ -0,0 +1,41 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) +--SKIPIF-- + +--FILE-- +"; + +$files = array(); +$files['a.php'] = ''; +$files['b.php'] = ''; +$files['b/c.php'] = ''; +$manifest = ''; +foreach($files as $name => $cont) { + $len = strlen($cont); + $manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00); +} +$alias = ''; +$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest; +$file .= pack('V', strlen($manifest)) . $manifest; +foreach($files as $cont) +{ + $file .= $cont; +} + +file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); + +$fp = fopen('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php'; +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php'; +?> + +===DONE=== +--CLEAN-- + +--EXPECT-- +This is b/c +extra +===DONE===