From a02afe32c10dea0cf4c48a2171730cba6cf971d0 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 21 Jan 2007 15:57:12 +0000 Subject: [PATCH] - Fix issues with metadata testing --- ext/phar/phar.c | 9 +++++---- ext/phar/tests/metadata_read.phpt | 33 +++++++++---------------------- ext/phar/tests/phar_test.inc | 23 ++++++++++++++++++--- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 2130d3c6cc..cb79ab4c85 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -391,6 +391,7 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z php_uint32 datatype; php_uint16 len; char *data; + do { /* for each meta-data, add an array index to the metadata array if the index already exists, convert to a sub-array */ @@ -404,18 +405,18 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z memcpy(data, *buffer, len); data[len] = '\0'; } - if (SUCCESS == zend_hash_index_find(metadata->value.ht, datatype, (void**)&found)) { + if (SUCCESS == zend_hash_index_find(HASH_OF(metadata), datatype, (void**)&found)) { if (Z_TYPE_P(found) == IS_ARRAY) { - add_next_index_stringl(dataarray, data, len, 0); + dataarray = found; } else { MAKE_STD_ZVAL(dataarray); array_init(dataarray); add_next_index_zval(dataarray, found); - add_next_index_stringl(dataarray, data, len, 0); } } else { - add_index_stringl(metadata, datatype, data, len, 0); + dataarray = metadata; } + add_index_stringl(dataarray, datatype, data, len, 0); } while (*(php_uint32 *) *buffer && *buffer < endbuffer); *buffer += 4; return SUCCESS; diff --git a/ext/phar/tests/metadata_read.phpt b/ext/phar/tests/metadata_read.phpt index 0a5b3be680..c9dbc7eb21 100644 --- a/ext/phar/tests/metadata_read.phpt +++ b/ext/phar/tests/metadata_read.phpt @@ -7,34 +7,19 @@ if (!extension_loaded("zlib")) print "skip zlib not present"; ?> phar.require_hash=0 --FILE-- "; -// file length is too short +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$file = ""; $files = array(); -$files['c'] = array('*', '*', 0x00000000); -$manifest = ''; -foreach($files as $name => $cont) { - $ulen = strlen($cont[0]); - $clen = strlen($cont[1]); - $manifest .= pack('V', strlen($name)) . $name - . pack('VVVVVVv', $ulen, time(), $clen, crc32($cont[0]), $cont[2], 1, strlen('hi there')) . 'hi there' . - pack('V', 0); -} -$alias = 'hio'; -$manifest = pack('VnVV', count($files), 0x0900, 0x00001000, strlen($alias)) . $alias . $manifest; -$file .= pack('V', strlen($manifest)) . $manifest; -foreach($files as $cont) -{ - $file .= $cont[1]; -} +$files['c'] = array('cont' => '*', 'meta' => array(1, 'hi there')); + +include 'phar_test.inc'; + +var_dump(file_get_contents($pname.'/c')); -file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file); -include dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; -var_dump(file_get_contents('phar://hio/c')); ?> --CLEAN-- --EXPECT-- -string(1) "*" \ No newline at end of file +string(1) "*" diff --git a/ext/phar/tests/phar_test.inc b/ext/phar/tests/phar_test.inc index 9f887dceb5..13b9c8b5a5 100755 --- a/ext/phar/tests/phar_test.inc +++ b/ext/phar/tests/phar_test.inc @@ -4,18 +4,35 @@ $manifest = ''; foreach($files as $name => $cont) { + $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006); + $perm = 0x000001B6; + $meta = array(); + if (is_array($cont)) + { + foreach(array('time','perm','meta','cont') as $what) + { + if (isset($cont[$what])) + { + $$what = $cont[$what]; + } + } + } $ulen = strlen($cont); $clen = $ulen; - $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006); $manifest .= pack('V', strlen($name)) . $name; - $manifest .= pack('VVVVVV', $ulen, $time, $clen, crc32($cont), 0x000001B6, 0); + $manifest .= pack('VVVVV', $ulen, $time, $clen, crc32($cont), $perm); + foreach($meta as $type => $data) + { + $manifest .= pack('Vv', $type, strlen($data)) . $data; + } + $manifest .= pack('V', 0); } $alias = 'hio'; $manifest = pack('VnVV', count($files), 0x0900, 0x00000000, strlen($alias)) . $alias . $manifest; $file .= pack('V', strlen($manifest)) . $manifest; foreach($files as $cont) { - $file .= $cont; + $file .= is_array($cont) ? $cont['cont'] : $cont; } file_put_contents($fname, $file); -- 2.40.0