From: Greg Beaver Date: Sun, 21 Jan 2007 06:54:04 +0000 (+0000) Subject: fix final memory leak, fix metadata reading (simple), add basic test that it doesn... X-Git-Tag: RELEASE_1_0_0RC1~178 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f21a0cdd0c921295e653b76e47de9bcebca6a4c9;p=php fix final memory leak, fix metadata reading (simple), add basic test that it doesn't break --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index bf3acb927f..7722e39e7f 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -663,8 +663,11 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z PHAR_GET_32(*buffer, datatype); PHAR_GET_16(*buffer, len); data = (char *) emalloc(len); - if (len != php_stream_read(fp, data, (size_t) len) TSRMLS_CC) { + if (endbuffer - *buffer < len) { + efree(data); return FAILURE; + } else { + memcpy(data, *buffer, len); } if (SUCCESS == zend_hash_index_find(metadata->value.ht, datatype, (void**)&found)) { if (Z_TYPE_P(found) == IS_ARRAY) { @@ -676,10 +679,8 @@ static int phar_parse_metadata(php_stream *fp, char **buffer, char *endbuffer, z add_next_index_stringl(dataarray, data, len, 0); } } else { - MAKE_STD_ZVAL(dataarray); add_index_stringl(metadata, 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 new file mode 100644 index 0000000000..0a5b3be680 --- /dev/null +++ b/ext/phar/tests/metadata_read.phpt @@ -0,0 +1,40 @@ +--TEST-- +Phar with meta-data (Read) +--SKIPIF-- + +--INI-- +phar.require_hash=0 +--FILE-- +"; +// file length is too short + +$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]; +} + +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