]> granicus.if.org Git - php/commitdiff
new test for central directory offset being wrong
authorGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 05:45:10 +0000 (05:45 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 05:45:10 +0000 (05:45 +0000)
ext/phar/tests/zip/corrupt_004.phpt [new file with mode: 0644]
ext/phar/tests/zip/files/cdir_offset.zip [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt_count1.php.inc
ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
ext/phar/tests/zip/files/count1.zip
ext/phar/tests/zip/files/count2.zip
ext/phar/tests/zip/files/filecomment.zip
ext/phar/tests/zip/files/nozipend.zip

diff --git a/ext/phar/tests/zip/corrupt_004.phpt b/ext/phar/tests/zip/corrupt_004.phpt
new file mode 100644 (file)
index 0000000..3760e8f
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Phar: corrupted zip (central directory offset incorrect)
+--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/cdir_offset.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: corrupted central directory entry, no magic signature in zip-based phar "%scdir_offset.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/files/cdir_offset.zip b/ext/phar/tests/zip/files/cdir_offset.zip
new file mode 100644 (file)
index 0000000..9172554
Binary files /dev/null and b/ext/phar/tests/zip/files/cdir_offset.zip differ
index 17a3a62e4914660afe8e495da6233fe5071782e2..314fdef6dbb23e0ecd46d379ed1a06d73944ef5a 100644 (file)
@@ -7,4 +7,5 @@ $a->writeZip(dirname(__FILE__) . '/count1.zip', 'count1');
 $a->writeZip(dirname(__FILE__) . '/count2.zip', 'count2');
 $a->writeZip(dirname(__FILE__) . '/nozipend.zip', 'none');
 $a->writeZip(dirname(__FILE__) . '/filecomment.zip', 'comment');
+$a->writeZip(dirname(__FILE__) . '/cdir_offset.zip', 'cdir_offset');
 ?>
index 98d99ce24d09579dab84279e88b864cda1aa6e66..3279176a95d4e1b7ed50b6ec46841256c073712f 100644 (file)
@@ -261,16 +261,16 @@ class corrupt_zipmaker
                                        $this->offset, strlen($this->start),
                                        strlen($this->comment)) . $this->comment;
                                break;
-                       case 'cdir_len' :
+                       case 'cdir_offset' :
                                $write .= "PK\x05\x06\x00\x00\x00\x00" .
                                        pack("vvVVv", $this->count, $this->count,
                                        $this->offset, strlen($this->start) - 3,
                                        strlen($this->comment)) . $this->comment;
                                break;
-                       case 'cdir_offset' :
+                       case 'cdir_len' :
                                $write .= "PK\x05\x06\x00\x00\x00\x00" .
                                        pack("vvVVv", $this->count, $this->count,
-                                       $this->offset + 1, strlen($this->start),
+                                       $this->offset - 5, strlen($this->start),
                                        strlen($this->comment)) . $this->comment;
                                break;
                        case 'comment' :
index 2a156cb3f51f6e11110eca3193577f3d39e43475..73b556103ab7524e13ee67b54a1cbed18659ef57 100644 (file)
Binary files a/ext/phar/tests/zip/files/count1.zip and b/ext/phar/tests/zip/files/count1.zip differ
index 0da6f9c7ba475676e8949ae8c2bc13925c844338..6aa2619539b929d8873298e73b277101586bfeee 100644 (file)
Binary files a/ext/phar/tests/zip/files/count2.zip and b/ext/phar/tests/zip/files/count2.zip differ
index d1f9bfb1efb29aa79441e26eff3c603ef8e71e3c..414b121fdca0fb72e6277ff56c4e9dad761879f0 100644 (file)
Binary files a/ext/phar/tests/zip/files/filecomment.zip and b/ext/phar/tests/zip/files/filecomment.zip differ
index d91268c6159207b686c996d3aa133aee46ab2a38..f97607221cd75ad1aab7a0fee9529759a9b02609 100644 (file)
Binary files a/ext/phar/tests/zip/files/nozipend.zip and b/ext/phar/tests/zip/files/nozipend.zip differ