--- /dev/null
+--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===
$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');
?>
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 :
$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 .
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) {
$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 .
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);
}
$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++;
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);
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) {