From: Greg Beaver Date: Thu, 8 Dec 2005 06:46:02 +0000 (+0000) Subject: add error if seeking fails on self, add test 1 for truncated phar X-Git-Tag: RELEASE_1_0_4~474 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16bd8c6ac732fcf0f024b99dd6ff742a9a459146;p=php add error if seeking fails on self, add test 1 for truncated phar --- 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