]> granicus.if.org Git - php/commitdiff
add error if seeking fails on self, add test 1 for truncated phar
authorGreg Beaver <cellog@php.net>
Thu, 8 Dec 2005 06:46:02 +0000 (06:46 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 8 Dec 2005 06:46:02 +0000 (06:46 +0000)
ext/phar/phar.c
ext/phar/tests/005.phpt [new file with mode: 0644]

index c750d21798299a40970ca2830d3a55e15a752f3e..b5231a2f44b6a966fac3564c6a43ea36aa0433e9 100644 (file)
@@ -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 (file)
index 0000000..2ec6c31
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+PHP_Archive::mapPhar improper parameters
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip";?>
+--FILE--
+<?php
+PHP_Archive::mapPhar(5, 'hio', false);
+__HALT_COMPILER();
+?>
+--EXPECTF--
+Fatal error: PHP_Archive::mapPhar(): internal corruption of phar "%s" (truncated manifest) in %s on line %d
\ No newline at end of file