From 16bd8c6ac732fcf0f024b99dd6ff742a9a459146 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Thu, 8 Dec 2005 06:46:02 +0000 Subject: [PATCH] add error if seeking fails on self, add test 1 for truncated phar --- ext/phar/phar.c | 9 ++++++--- ext/phar/tests/005.phpt | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 ext/phar/tests/005.phpt diff --git a/ext/phar/phar.c b/ext/phar/phar.c index c750d21798..b5231a2f44 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -159,15 +159,18 @@ PHP_METHOD(PHP_Archive, mapPhar) php_error_docref(NULL TSRMLS_CC, E_ERROR, "unable to open phar for reading \"%s\"", fname); return; } - - // check for ?>\n and increment accordingly - php_stream_seek(fp, halt_offset, SEEK_SET); #define MAPPHAR_ALLOC_FAIL(msg) php_stream_close(fp);\ php_stream_close(fp);\ php_error_docref(NULL TSRMLS_CC, E_ERROR, msg, fname);\ return; #define MAPPHAR_FAIL(msg) efree(buffer);\ MAPPHAR_ALLOC_FAIL(msg) + + // check for ?>\n and increment accordingly + if (0 == php_stream_seek(fp, halt_offset, SEEK_SET)) { + MAPPHAR_FAIL("cannot seek to __HALT_COMPILER() location in phar \"%s\"") + } + if (FALSE == (buffer = (char *) emalloc(4))) { MAPPHAR_ALLOC_FAIL("memory allocation failed in phar \"%s\"") } diff --git a/ext/phar/tests/005.phpt b/ext/phar/tests/005.phpt new file mode 100644 index 0000000000..2ec6c315a4 --- /dev/null +++ b/ext/phar/tests/005.phpt @@ -0,0 +1,11 @@ +--TEST-- +PHP_Archive::mapPhar improper parameters +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: PHP_Archive::mapPhar(): internal corruption of phar "%s" (truncated manifest) in %s on line %d \ No newline at end of file -- 2.50.1