]> granicus.if.org Git - php/commitdiff
new test for encrypted zips
authorGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 05:51:10 +0000 (05:51 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 05:51:10 +0000 (05:51 +0000)
ext/phar/tests/zip/corrupt_005.phpt [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt2.php.inc [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
ext/phar/tests/zip/files/encrypted.zip [new file with mode: 0644]

diff --git a/ext/phar/tests/zip/corrupt_005.phpt b/ext/phar/tests/zip/corrupt_005.phpt
new file mode 100644 (file)
index 0000000..6b5d31d
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Phar: encrypted zip
+--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/encrypted.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: Cannot process encrypted zip files in zip-based phar "%sencrypted.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/files/corrupt2.php.inc b/ext/phar/tests/zip/files/corrupt2.php.inc
new file mode 100644 (file)
index 0000000..b396d58
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+include dirname(__FILE__) . '/corrupt_zipmaker.php.inc';
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii');
+$a->addFile('hi2', null, 'hii2', null, null, 'encrypt', 'encrypt');
+$a->writeZip(dirname(__FILE__) . '/encrypted.zip');
+?>
index 3279176a95d4e1b7ed50b6ec46841256c073712f..0a8cab6e8f782f81fb9e0046c02eebaab4e50b8b 100644 (file)
@@ -94,6 +94,13 @@ class corrupt_zipmaker
                                                $filename .
                                                $data;
                                break;
+                       case 'encrypt' :
+                               $file = "PK\x03\x04\x14\x00\x01\x00" . pack('v', $compmethod) .
+                                               $mtime .
+                                               pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+                                               $filename .
+                                               $data;
+                               break;
                        case 'crc32' :
                                $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $compmethod) .
                                                $mtime .
@@ -159,6 +166,14 @@ class corrupt_zipmaker
                                                $filename . $comment;
                                $offset = strlen($central);
                                break;
+                       case 'encrypt' :
+                               $central = "PK\x01\x02\x00\x00\x14\x00\x01\x00" . pack('v', $compmethod) .
+                                               $mtime .
+                                               pack("VVVvvvvvVV", $crc32, $complength, $uncomplength, strlen($filename), 0x00,strlen($comment),0x00,0x00,
+                                                       0x0000, $this->offset).
+                                               $filename . $comment;
+                               $offset = strlen($central);
+                               break;
                        case 'crc32' :
                                $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $compmethod) .
                                                $mtime .
diff --git a/ext/phar/tests/zip/files/encrypted.zip b/ext/phar/tests/zip/files/encrypted.zip
new file mode 100644 (file)
index 0000000..00aed14
Binary files /dev/null and b/ext/phar/tests/zip/files/encrypted.zip differ