From ca86d4fa921ec7ff26cd441da26e7a1f199d5f28 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sun, 11 Dec 2005 00:00:31 +0000 Subject: [PATCH] switch to php_stream_wrapper_log_error from php_error_docref (should be documented somewhere...), add test for failing stream open --- ext/phar/phar.c | 47 +++++++++++++++++++++++++---------------- ext/phar/tests/013.phpt | 2 +- ext/phar/tests/014.phpt | 2 +- ext/phar/tests/016.phpt | 21 ++++++++++++++++++ 4 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 ext/phar/tests/016.phpt diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 196b44ee11..211bdd2021 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -537,7 +537,7 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe if (resource) { php_url_free(resource); } - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: invalid url \"%s\"", path); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", path); return NULL; } @@ -545,7 +545,7 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe if (resource) { php_url_free(resource); } - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: not a phar stream url \"%s\"", path); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar stream url \"%s\"", path); return NULL; } @@ -574,7 +574,7 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe buffer = idata->data->file; efree(idata); efree(internal_file); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: cannot open phar \"%s\"", buffer); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot open phar \"%s\"", buffer); return NULL; } @@ -584,9 +584,10 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe buffer = idata->data->file; offset = idata->data->internal_file_start + idata->internal_file->offset_within_phar; efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (cannot seek to start of file \"%s\" at offset \"%d\")", + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (cannot seek to start of file \"%s\" at offset \"%d\")", buffer, internal_file, offset); + efree(internal_file); return NULL; } if (idata->data->is_compressed) { @@ -597,7 +598,8 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe php_stream_close(fp); buffer = idata->data->file; efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } php_stream_close(fp); @@ -626,7 +628,8 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe buffer = idata->data->file; efree(idata->file); efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (corrupted zlib compression of file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (corrupted zlib compression of file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } @@ -658,7 +661,7 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe efree(idata->file); efree(idata); efree(internal_file); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "phar error: %s", zError(status)); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: %s", zError(status)); return NULL; } #define PHAR_ZLIB_ERROR efree(savebuf);\ @@ -671,25 +674,30 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe /* check length */ if (actual_length != idata->internal_file->uncompressed_filesize) { PHAR_ZLIB_ERROR - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); + return NULL; } /* check crc32/filesize */ if (!idata->internal_file->crc_checked) { status = phar_postprocess_file(idata->file, idata->internal_file->uncompressed_filesize, crc32, 0); if (-1 == status) { PHAR_ZLIB_ERROR - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } if (-2 == status) { PHAR_ZLIB_ERROR - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } idata->internal_file->crc_checked = 1; } #else - php_error_docref(NULL TSRMLS_CC, E_ERROR, "zlib extension must be enabled for compressed .phar files"); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "zlib extension must be enabled for compressed .phar files"); + efree(internal_file); return NULL; #endif } else { @@ -700,7 +708,8 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe efree(idata->file); buffer = idata->data->file; efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } php_stream_close(fp); @@ -711,14 +720,16 @@ PHP_PHAR_API php_stream * php_stream_phar_url_wrapper(php_stream_wrapper *wrappe efree(idata->file); buffer = idata->data->file; efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } if (-2 == status) { efree(idata->file); buffer = idata->data->file; efree(idata); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (filesize mismatch on file \"%s\")", buffer, internal_file); + efree(internal_file); return NULL; } idata->internal_file->crc_checked = 1; @@ -904,14 +915,14 @@ PHP_PHAR_API int phar_stream_stat(php_stream_wrapper *wrapper, char *url, int fl /* we must have at the very least phar://alias.phar/internalfile.php */ if (!resource || !resource->scheme || !resource->host || !resource->path) { php_url_free(resource); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: invalid url \"%s\"", url); + php_stream_wrapper_log_error(wrapper, flags TSRMLS_CC, "phar error: invalid url \"%s\"", url); php_url_free(resource); return -1; } if (strcasecmp("phar", resource->scheme)) { php_url_free(resource); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: not a phar url \"%s\"", url); + php_stream_wrapper_log_error(wrapper, flags TSRMLS_CC, "phar error: not a phar url \"%s\"", url); return -1; } @@ -1025,13 +1036,13 @@ PHP_PHAR_API php_stream *phar_opendir(php_stream_wrapper *wrapper, char *filenam /* we must have at the very least phar://alias.phar/internalfile.php */ if (!resource || !resource->scheme || !resource->host || !resource->path) { php_url_free(resource); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: invalid url \"%s\"", filename); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", filename); return NULL; } if (strcasecmp("phar", resource->scheme)) { php_url_free(resource); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "phar error: not a phar url \"%s\"", filename); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar url \"%s\"", filename); return NULL; } diff --git a/ext/phar/tests/013.phpt b/ext/phar/tests/013.phpt index 94d109912e..9c97cd08a4 100644 --- a/ext/phar/tests/013.phpt +++ b/ext/phar/tests/013.phpt @@ -17,4 +17,4 @@ include dirname(__FILE__) . '/008_phar.php'; echo file_get_contents('phar://hio/a'); ?> --EXPECTF-- -Fatal error: file_get_contents(): phar error: internal corruption of phar "%s" (filesize mismatch on file "a") in %s on line 12 \ No newline at end of file +Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (filesize mismatch on file "a") in %s on line 12 \ No newline at end of file diff --git a/ext/phar/tests/014.phpt b/ext/phar/tests/014.phpt index a59507705c..0959a66df7 100644 --- a/ext/phar/tests/014.phpt +++ b/ext/phar/tests/014.phpt @@ -17,4 +17,4 @@ include dirname(__FILE__) . '/008_phar.php'; echo file_get_contents('phar://hio/a'); ?> --EXPECTF-- -Fatal error: file_get_contents(): phar error: internal corruption of phar "%s" (crc32 mismatch on file "a") in %s on line 12 \ No newline at end of file +Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: internal corruption of phar "%s" (crc32 mismatch on file "a") in %s on line 12 \ No newline at end of file diff --git a/ext/phar/tests/016.phpt b/ext/phar/tests/016.phpt new file mode 100644 index 0000000000..0cbe5a336b --- /dev/null +++ b/ext/phar/tests/016.phpt @@ -0,0 +1,21 @@ +--TEST-- +PHP_Archive::mapPhar valid file (gzipped) +--SKIPIF-- + +--FILE-- +"; +// file length is too short +$manifest = pack('V', 1) . 'a' . pack('VVVV', 1, time(), 0, 9); +$file .= pack('VV', strlen($manifest) + 4, 1) . $manifest . pack('VV', crc32('a'), 1) . chr(75) . chr(4) . chr(0); // 'a' gzdeflated +file_put_contents(dirname(__FILE__) . '/008_phar.php', $file); +include dirname(__FILE__) . '/008_phar.php'; +echo file_get_contents('phar://hio/a'); +?> +--EXPECTF-- +Warning: file_get_contents(phar://hio/a): failed to open stream: phar error: data error in %s on line %d \ No newline at end of file -- 2.50.1