]> granicus.if.org Git - php/commitdiff
new test for unsupported compression versions, vastly enhance error messages on unsup...
authorGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 06:18:13 +0000 (06:18 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 19 Apr 2008 06:18:13 +0000 (06:18 +0000)
22 files changed:
ext/phar/tests/zip/corrupt_008.phpt [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup1.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup10.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup14.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup18.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup19.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup2.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup3.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup4.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup5.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup6.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup7.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup9.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup97.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsup98.zip [new file with mode: 0644]
ext/phar/tests/zip/files/compress_unsupunknown.zip [new file with mode: 0644]
ext/phar/tests/zip/files/corrupt2.php.inc
ext/phar/tests/zip/files/corrupt_zipmaker.php.inc
ext/phar/tests/zip/files/encrypted.zip
ext/phar/tests/zip/files/stdin.zip
ext/phar/tests/zip/files/truncfilename.zip
ext/phar/zip.c

diff --git a/ext/phar/tests/zip/corrupt_008.phpt b/ext/phar/tests/zip/corrupt_008.phpt
new file mode 100644 (file)
index 0000000..5a20f4d
--- /dev/null
@@ -0,0 +1,101 @@
+--TEST--
+Phar: unsupported compression methods
+--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/compress_unsup1.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup2.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup3.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup4.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup5.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup6.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup7.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup9.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup10.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup14.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup18.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup19.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup97.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsup98.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+try {
+       new PharData(dirname(__FILE__) . '/files/compress_unsupunknown.zip');
+} catch (Exception $e) {
+       echo $e->getMessage() . "\n";
+}
+?>
+===DONE===
+--EXPECTF--
+phar error: unsupported compression method (Shrunk) used in this zip in zip-based phar "%scompress_unsup1.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup2.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup3.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup4.zip"
+phar error: unsupported compression method (Reduce) used in this zip in zip-based phar "%scompress_unsup5.zip"
+phar error: unsupported compression method (Implode) used in this zip in zip-based phar "%scompress_unsup6.zip"
+phar error: unsupported compression method (Tokenize) used in this zip in zip-based phar "%scompress_unsup7.zip"
+phar error: unsupported compression method (Deflate64) used in this zip in zip-based phar "%scompress_unsup9.zip"
+phar error: unsupported compression method (PKWare Implode/old IBM TERSE) used in this zip in zip-based phar "%scompress_unsup10.zip"
+phar error: unsupported compression method (LZMA) used in this zip in zip-based phar "%scompress_unsup14.zip"
+phar error: unsupported compression method (IBM TERSE) used in this zip in zip-based phar "%scompress_unsup18.zip"
+phar error: unsupported compression method (IBM LZ77) used in this zip in zip-based phar "%scompress_unsup19.zip"
+phar error: unsupported compression method (WavPack) used in this zip in zip-based phar "%scompress_unsup97.zip"
+phar error: unsupported compression method (PPMd) used in this zip in zip-based phar "%scompress_unsup98.zip"
+phar error: unsupported compression method (unknown) used in this zip in zip-based phar "%scompress_unsupunknown.zip"
+===DONE===
diff --git a/ext/phar/tests/zip/files/compress_unsup1.zip b/ext/phar/tests/zip/files/compress_unsup1.zip
new file mode 100644 (file)
index 0000000..bd1f72b
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup1.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup10.zip b/ext/phar/tests/zip/files/compress_unsup10.zip
new file mode 100644 (file)
index 0000000..2a7f221
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup10.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup14.zip b/ext/phar/tests/zip/files/compress_unsup14.zip
new file mode 100644 (file)
index 0000000..d494143
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup14.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup18.zip b/ext/phar/tests/zip/files/compress_unsup18.zip
new file mode 100644 (file)
index 0000000..7ef2217
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup18.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup19.zip b/ext/phar/tests/zip/files/compress_unsup19.zip
new file mode 100644 (file)
index 0000000..8086d45
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup19.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup2.zip b/ext/phar/tests/zip/files/compress_unsup2.zip
new file mode 100644 (file)
index 0000000..d827d2d
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup2.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup3.zip b/ext/phar/tests/zip/files/compress_unsup3.zip
new file mode 100644 (file)
index 0000000..d4acc60
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup3.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup4.zip b/ext/phar/tests/zip/files/compress_unsup4.zip
new file mode 100644 (file)
index 0000000..76a4dc1
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup4.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup5.zip b/ext/phar/tests/zip/files/compress_unsup5.zip
new file mode 100644 (file)
index 0000000..d42155d
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup5.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup6.zip b/ext/phar/tests/zip/files/compress_unsup6.zip
new file mode 100644 (file)
index 0000000..5084640
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup6.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup7.zip b/ext/phar/tests/zip/files/compress_unsup7.zip
new file mode 100644 (file)
index 0000000..65c2e23
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup7.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup9.zip b/ext/phar/tests/zip/files/compress_unsup9.zip
new file mode 100644 (file)
index 0000000..df0c767
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup9.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup97.zip b/ext/phar/tests/zip/files/compress_unsup97.zip
new file mode 100644 (file)
index 0000000..907f365
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup97.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsup98.zip b/ext/phar/tests/zip/files/compress_unsup98.zip
new file mode 100644 (file)
index 0000000..54f19fb
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsup98.zip differ
diff --git a/ext/phar/tests/zip/files/compress_unsupunknown.zip b/ext/phar/tests/zip/files/compress_unsupunknown.zip
new file mode 100644 (file)
index 0000000..1706954
Binary files /dev/null and b/ext/phar/tests/zip/files/compress_unsupunknown.zip differ
index 27b2f15412d0a921a2ae817c9cf2467cb11dffc3..3edf6203100b074b816799e21ae62c0035e7a0e2 100644 (file)
@@ -12,4 +12,49 @@ $a = new corrupt_zipmaker;
 $a->addFile('hii', null, 'hii', null, null, 'filename_len', 'filename_len');
 $a->addFile('hi', null, 'hii');
 $a->writeZip(dirname(__FILE__) . '/truncfilename.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress');
+$a->writeZip(dirname(__FILE__) . '/compress_unsup1.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 2);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup2.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 3);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup3.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 4);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup4.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 5);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup5.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 6);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup6.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 7);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup7.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 9);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup9.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 10);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup10.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 14);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup14.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 18);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup18.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 19);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup19.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 97);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup97.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 98);
+$a->writeZip(dirname(__FILE__) . '/compress_unsup98.zip');
+$a = new corrupt_zipmaker;
+$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 11);
+$a->writeZip(dirname(__FILE__) . '/compress_unsupunknown.zip');
 ?>
index 0a8cab6e8f782f81fb9e0046c02eebaab4e50b8b..2c1719920de3a2907008ab18a716d65ad5dfaad6 100644 (file)
@@ -84,7 +84,7 @@ class corrupt_zipmaker
                return $mtime;
        }
 
-       private function getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $corrupt)
+       private function getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $corrupt, $fakecomp)
        {
                switch ($corrupt) {
                        case null :
@@ -94,6 +94,13 @@ class corrupt_zipmaker
                                                $filename .
                                                $data;
                                break;
+                       case 'compress' :
+                               $file = "PK\x03\x04\x14\x00\x00\x00" . pack('v', $fakecomp) .
+                                               $mtime .
+                                               pack("VVVvv", $crc32, $complength, $uncomplength, strlen($filename), 0x00) .
+                                               $filename .
+                                               $data;
+                               break;
                        case 'encrypt' :
                                $file = "PK\x03\x04\x14\x00\x01\x00" . pack('v', $compmethod) .
                                                $mtime .
@@ -154,7 +161,7 @@ class corrupt_zipmaker
                return $file;
        }
 
-       private function getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $corrupt, &$offset)
+       private function getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $corrupt, &$offset, $fakecomp)
        {
                settype($comment, 'string');
                switch ($corrupt) {
@@ -174,6 +181,14 @@ class corrupt_zipmaker
                                                $filename . $comment;
                                $offset = strlen($central);
                                break;
+                       case 'compress' :
+                               $central = "PK\x01\x02\x00\x00\x14\x00\x00\x00" . pack('v', $fakecomp) .
+                                               $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 .
@@ -226,7 +241,7 @@ class corrupt_zipmaker
                return $central;
        }
 
-       function addFile($filename, $mtime, $data, $comment = null, $compress = null, $filecorrupt = null, $centralcorrupt = null)
+       function addFile($filename, $mtime, $data, $comment = null, $compress = null, $filecorrupt = null, $centralcorrupt = null, $fakecomp = 1)
        {
                $mtime = $this->getMTime($mtime ? $mtime : null);
 
@@ -245,10 +260,10 @@ class corrupt_zipmaker
                }
                $complength = strlen($data);
 
-               $this->start .= ($file = $this->getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $filecorrupt));
+               $this->start .= ($file = $this->getFileEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $data, $filecorrupt, $fakecomp));
 
                $offset = 0;
-               $this->central .= $this->getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $centralcorrupt, $offset);
+               $this->central .= $this->getCentralEntry($compmethod, $mtime, $crc32, $complength, $uncomplength, $filename, $comment, $centralcorrupt, $offset, $fakecomp);
 
                $this->offset += $offset;
                $this->count++;
index 99a38c821a3d399ed8aafa3e5c0801799951c70a..dee73cad37083807ac6e234f87e5dc9af747c728 100644 (file)
Binary files a/ext/phar/tests/zip/files/encrypted.zip and b/ext/phar/tests/zip/files/encrypted.zip differ
index 836b74d8cd9fc3da5005fa43732e0b8b65f3df60..4376eb67fa50e89d221cffd7f29761e66844e07b 100644 (file)
Binary files a/ext/phar/tests/zip/files/stdin.zip and b/ext/phar/tests/zip/files/stdin.zip differ
index 1682e1f0aaf9e6335ac4ba3e7da0f097e79f848c..d8a526a4bb4319bf09a1606e1e93891b36595fcc 100644 (file)
Binary files a/ext/phar/tests/zip/files/truncfilename.zip and b/ext/phar/tests/zip/files/truncfilename.zip differ
index 6724cf6825b745b675a1d2355bb2986e631bc4a1..0d3a207611ef38668f9a9608cb0de7f0a2b8a5e3 100644 (file)
@@ -304,6 +304,7 @@ foundit:
                if (PHAR_GET_16(zipentry.extra_len)) {
                        off_t loc = php_stream_tell(fp);
                        if (FAILURE == phar_zip_process_extra(fp, &entry, PHAR_GET_16(zipentry.extra_len) TSRMLS_CC)) {
+                               efree(entry.filename);
                                PHAR_ZIP_FAIL("Unable to process extra field header for file in central directory");
                        }
                        php_stream_seek(fp, loc + PHAR_GET_16(zipentry.extra_len), SEEK_SET);
@@ -324,8 +325,45 @@ foundit:
                                        PHAR_ZIP_FAIL("bzip2 extension is required");
                                }
                                break;
+                       case 1 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (Shrunk) used in this zip");
+                       case 2 :
+                       case 3 :
+                       case 4 :
+                       case 5 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (Reduce) used in this zip");
+                       case 6 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (Implode) used in this zip");
+                       case 7 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (Tokenize) used in this zip");
+                       case 9 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (Deflate64) used in this zip");
+                       case 10 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (PKWare Implode/old IBM TERSE) used in this zip");
+                       case 14 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (LZMA) used in this zip");
+                       case 18 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (IBM TERSE) used in this zip");
+                       case 19 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (IBM LZ77) used in this zip");
+                       case 97 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (WavPack) used in this zip");
+                       case 98 :
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (PPMd) used in this zip");
                        default :
-                               PHAR_ZIP_FAIL("unsupported compression method used in this zip");
+                               efree(entry.filename);
+                               PHAR_ZIP_FAIL("unsupported compression method (unknown) used in this zip");
                }
                /* get file metadata */
                if (zipentry.comment_len) {