From: Greg Beaver Date: Wed, 9 Jan 2008 08:45:00 +0000 (+0000) Subject: fix gzipped phars in phar file format, add test X-Git-Tag: RELEASE_2_0_0a1~970 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21ab2ca8e99f8ddea0d56ff7140f39d946d50c5c;p=php fix gzipped phars in phar file format, add test --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 2c6f12edd7..c61e404bd5 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2981,7 +2981,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error if (!phar->fp) { phar->fp = newfile; if (error) { - spprintf(error, 0, "unable to open new phar \"%s\" for writing", phar->fname); + spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname); } return EOF; } @@ -2991,9 +2991,15 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error zval filterparams; array_init(&filterparams); - add_assoc_long(&filterparams, "window", MAX_WBITS); + add_assoc_long(&filterparams, "window", MAX_WBITS+16); filter = php_stream_filter_create("zlib.deflate", &filterparams, php_stream_is_persistent(phar->fp) TSRMLS_CC); zval_dtor(&filterparams); + if (!filter) { + if (error) { + spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname); + } + return EOF; + } php_stream_filter_append(&phar->fp->writefilters, filter); php_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL); php_stream_filter_flush(filter, 1); @@ -3052,6 +3058,12 @@ static void php_phar_init_globals_module(zend_phar_globals *phar_globals) } /* }}} */ +static long stream_fteller_for_zend(void *handle TSRMLS_DC) /* {{{ */ +{ + return (long)php_stream_tell((php_stream*)handle); +} +/* }}} */ + static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */ { zend_op_array *res; @@ -3083,6 +3095,17 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type *file_handle = f; } goto skip_phar; + } else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) { + /* compressed phar */ + file_handle->type = ZEND_HANDLE_STREAM; + file_handle->free_filename = 0; + file_handle->handle.stream.handle = phar->fp; + file_handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read; + file_handle->handle.stream.closer = NULL; /* don't close - let phar handle this one */ + file_handle->handle.stream.fteller = stream_fteller_for_zend; + file_handle->handle.stream.interactive = 0; + php_stream_rewind(phar->fp); + goto skip_phar; } } } diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 182892a8ed..f9afe72df1 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -569,9 +569,15 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er zval filterparams; array_init(&filterparams); - add_assoc_long(&filterparams, "window", MAX_WBITS); + add_assoc_long(&filterparams, "window", MAX_WBITS + 16); filter = php_stream_filter_create("zlib.deflate", &filterparams, php_stream_is_persistent(phar->fp) TSRMLS_CC); zval_dtor(&filterparams); + if (!filter) { + if (error) { + spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname); + } + return EOF; + } php_stream_filter_append(&phar->fp->writefilters, filter); php_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL); php_stream_filter_flush(filter, 1); diff --git a/ext/phar/tests/phar_gzip.phpt b/ext/phar/tests/phar_gzip.phpt new file mode 100644 index 0000000000..f521ec86e3 --- /dev/null +++ b/ext/phar/tests/phar_gzip.phpt @@ -0,0 +1,53 @@ +--TEST-- +Phar: gzipped phar +--SKIPIF-- + + + + +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +isPhar()); +var_dump($b->isCompressed() == Phar::GZ); +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +string(9) "it worked" +string(%d) "phar://%sphar_gzip.phar/tar_004.php" +bool(true) +bool(true) +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/phar_test.inc b/ext/phar/tests/phar_test.inc index af5d227f66..2c3062c457 100755 --- a/ext/phar/tests/phar_test.inc +++ b/ext/phar/tests/phar_test.inc @@ -61,4 +61,10 @@ foreach($files as $cont) file_put_contents($fname, $file); +if (@$gzip) { + $fp = gzopen($fname, 'w'); + fwrite($fp, $file); + fclose($fp); +} + ?> \ No newline at end of file diff --git a/ext/phar/tests/tar/tar_gzip.phpt b/ext/phar/tests/tar/tar_gzip.phpt index 730adc6807..9fccc79226 100644 --- a/ext/phar/tests/tar/tar_gzip.phpt +++ b/ext/phar/tests/tar/tar_gzip.phpt @@ -4,6 +4,7 @@ Phar: tar-based phar, gzipped tar + --INI-- phar.readonly=0 --FILE-- @@ -33,9 +34,8 @@ $a = new Phar($fname); $a['test'] = 'hi'; copy($fname, $fname2); $b = new Phar($fname2); -var_dump($b->isCompressed == Phar::GZ); - -__HALT_COMPILER(); +var_dump($b->isTar()); +var_dump($b->isCompressed() == Phar::GZ); ?> ===DONE=== --CLEAN-- @@ -47,4 +47,5 @@ __HALT_COMPILER(); string(9) "it worked" string(%d) "phar://%star_gzip.phar/tar_004.php" bool(true) +bool(true) ===DONE=== \ No newline at end of file