]> granicus.if.org Git - php/commitdiff
add failing test for truncated tar archive
authorGreg Beaver <cellog@php.net>
Sun, 20 Apr 2008 15:12:09 +0000 (15:12 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 20 Apr 2008 15:12:09 +0000 (15:12 +0000)
ext/phar/tar.c
ext/phar/tests/tar/truncated.phpt [new file with mode: 0644]

index 17b6a7e9fcfba31dbce13f73c14241c8b977f9cf..343ee2b14bb4928c62ec800cfbdca60bb0086ff5 100644 (file)
@@ -164,7 +164,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
        read = php_stream_read(fp, buf, sizeof(buf));
        if (read != sizeof(buf)) {
                if (error) {
-                       spprintf(error, 4096, "phar error: \"%s\" is not a tar file", fname);
+                       spprintf(error, 4096, "phar error: \"%s\" is not a tar file or is truncated", fname);
                }
                php_stream_close(fp);
                return FAILURE;
@@ -187,7 +187,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
        do {
                if (read != sizeof(buf)) {
                        if (error) {
-                               spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file", fname);
+                               spprintf(error, 4096, "phar error: \"%s\" is a corrupted tar file (truncated)", fname);
                        }
                        php_stream_close(fp);
                        zend_hash_destroy(&myphar->manifest);
diff --git a/ext/phar/tests/tar/truncated.phpt b/ext/phar/tests/tar/truncated.phpt
new file mode 100644 (file)
index 0000000..fbcabb7
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Phar: truncated tar
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+try {
+       $p = new PharData(dirname(__FILE__) . '/files/trunc.tar');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');
+?>
+--EXPECTF--
+phar error: "%strunc.tar" is a corrupted tar file (truncated)
+===DONE===