]> granicus.if.org Git - php/commitdiff
MFB increase code coverage
authorGreg Beaver <cellog@php.net>
Thu, 21 Aug 2008 20:36:21 +0000 (20:36 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 21 Aug 2008 20:36:21 +0000 (20:36 +0000)
ext/phar/tests/zip/corrupt_009.phpt [new file with mode: 0644]
ext/phar/tests/zip/corrupt_010.phpt [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt3.php.inc [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
ext/phar/tests/zip/files/disknumber.zip [new file with mode: 0644]
ext/phar/tests/zip/files/extralen_toolong.zip [new file with mode: 0644]

diff --git a/ext/phar/tests/zip/corrupt_009.phpt b/ext/phar/tests/zip/corrupt_009.phpt
new file mode 100644 (file)
index 0000000..91f142d
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (extra field way too long)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+       new PharData(dirname(__FILE__) . '/files/extralen_toolong.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: Unable to process extra field header for file in central directory in zip-based phar "%sextralen_toolong.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/corrupt_010.phpt b/ext/phar/tests/zip/corrupt_010.phpt
new file mode 100644 (file)
index 0000000..ead723c
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Phar: unable to process zip (zip spanning multiple archives)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--FILE--
+<?php
+try {
+       new PharData(dirname(__FILE__) . '/files/disknumber.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: split archives spanning multiple zips cannot be processed in zip-based phar "%sdisknumber.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/files/corrupt3.php.inc b/ext/phar/tests/zip/files/corrupt3.php.inc
new file mode 100644 (file)
index 0000000..05ba70b
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, null, 'extralen1');
+$a->writeZip(dirname(__FILE__) . '/extralen_toolong.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->writeZip(dirname(__FILE__) . '/disknumber.zip', 'disknumber');
+?>
index 2c1719920de3a2907008ab18a716d65ad5dfaad6..9fbfe341c3cf5ed3b857f06839de7d484b915e05 100644 (file)
@@ -237,6 +237,15 @@ class corrupt_zipmaker
                                                $filename . $comment;
                                $offset = strlen($central);
                                break;
+                       case 'extralen1' :
+                               $extra = 'nu' . 0xffff; // way huge size
+                               $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
+                                               $mtime .
+                                               pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), strlen($extra),strlen($comment),0x00,0x00,
+                                                       0x0000, $this->offset).
+                                               $filename . $extra . $comment;
+                               $offset = strlen($central);
+                               break;
                }
                return $central;
        }
@@ -279,6 +288,12 @@ class corrupt_zipmaker
                                        $this->offset, strlen($this->start),
                                        strlen($this->comment)) . $this->comment;
                                break;
+                       case 'disknumber' :
+                               $write .= "PK\x05\x06\x01\x00\x01\x00" .
+                                       pack("vvVVv", $this->count, $this->count,
+                                       $this->offset, strlen($this->start),
+                                       strlen($this->comment)) . $this->comment;
+                               break;
                        case 'count1' :
                                $write .= "PK\x05\x06\x00\x00\x00\x00" .
                                        pack("vvVVv", $this->count + 1, $this->count,
diff --git a/ext/phar/tests/zip/files/disknumber.zip b/ext/phar/tests/zip/files/disknumber.zip
new file mode 100644 (file)
index 0000000..f20db05
Binary files /dev/null and b/ext/phar/tests/zip/files/disknumber.zip differ
diff --git a/ext/phar/tests/zip/files/extralen_toolong.zip b/ext/phar/tests/zip/files/extralen_toolong.zip
new file mode 100644 (file)
index 0000000..a03a403
Binary files /dev/null and b/ext/phar/tests/zip/files/extralen_toolong.zip differ