1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-06 15:36:28 +02:00
This commit is contained in:
wapplay
2018-10-09 10:17:54 +03:00
parent f9e6a73587
commit e1866215a6
11 changed files with 24 additions and 14 deletions

View File

@@ -21,6 +21,7 @@
} }
], ],
"require": { "require": {
"ext-zlib": "*",
"php": "^5.5 || ^7.0", "php": "^5.5 || ^7.0",
"psr/http-message": "^1.0" "psr/http-message": "^1.0"
}, },

View File

@@ -179,9 +179,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
{ {
if (extension_loaded("openssl")) { if (extension_loaded("openssl")) {
$numBits = strlen($key) * 8; $numBits = strlen($key) * 8;
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_encrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv); return openssl_encrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
} elseif (extension_loaded("mcrypt")) { } elseif (extension_loaded("mcrypt")) {
/** @noinspection PhpDeprecationInspection */ /** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv); return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
} else { } else {
throw new RuntimeException('Extension openssl or mcrypt not loaded'); throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -200,9 +202,11 @@ class WinZipAesEngine implements ZipEncryptionEngine
{ {
if (extension_loaded("openssl")) { if (extension_loaded("openssl")) {
$numBits = strlen($key) * 8; $numBits = strlen($key) * 8;
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_decrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv); return openssl_decrypt($data, 'AES-' . $numBits . '-CTR', $key, OPENSSL_RAW_DATA, $iv);
} elseif (extension_loaded("mcrypt")) { } elseif (extension_loaded("mcrypt")) {
/** @noinspection PhpDeprecationInspection */ /** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv); return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, "ctr", $iv);
} else { } else {
throw new RuntimeException('Extension openssl or mcrypt not loaded'); throw new RuntimeException('Extension openssl or mcrypt not loaded');
@@ -220,7 +224,7 @@ class WinZipAesEngine implements ZipEncryptionEngine
{ {
// Init key strength. // Init key strength.
$password = $this->entry->getPassword(); $password = $this->entry->getPassword();
if ($password === null){ if ($password === null) {
throw new ZipException('No password was set for the entry "'.$this->entry->getName().'"'); throw new ZipException('No password was set for the entry "'.$this->entry->getName().'"');
} }

View File

@@ -152,7 +152,7 @@ class ExtraFieldsCollection implements \Countable, \ArrayAccess, \Iterator
public function offsetSet($offset, $value) public function offsetSet($offset, $value)
{ {
if ($value instanceof ExtraField) { if ($value instanceof ExtraField) {
if ($offset !== $value::getHeaderId()){ if ($offset !== $value::getHeaderId()) {
throw new InvalidArgumentException("Value header id !== array access key"); throw new InvalidArgumentException("Value header id !== array access key");
} }
$this->add($value); $this->add($value);

View File

@@ -48,6 +48,7 @@ class ZipChangesEntry extends ZipAbstractEntry
* Returns an string content of the given entry. * Returns an string content of the given entry.
* *
* @return null|string * @return null|string
* @throws ZipException
*/ */
public function getEntryContent() public function getEntryContent()
{ {

View File

@@ -57,7 +57,6 @@ class ZipSourceEntry extends ZipAbstractEntry
* Returns an string content of the given entry. * Returns an string content of the given entry.
* *
* @return string * @return string
* @throws ZipException
*/ */
public function getEntryContent() public function getEntryContent()
{ {
@@ -74,7 +73,7 @@ class ZipSourceEntry extends ZipAbstractEntry
} }
if (is_resource($this->entryContent)) { if (is_resource($this->entryContent)) {
rewind($this->entryContent); rewind($this->entryContent);
return stream_get_contents($this->entryContent, -1, 0); return stream_get_contents($this->entryContent);
} }
return $this->entryContent; return $this->entryContent;
} }

View File

@@ -1,4 +1,4 @@
<?php <?php /** @noinspection PhpMissingBreakStatementInspection */
namespace PhpZip\Model; namespace PhpZip\Model;
@@ -233,8 +233,6 @@ class ZipInfo
$xattr = (($externalAttributes >> 16) & 0xFFFF); $xattr = (($externalAttributes >> 16) & 0xFFFF);
switch ($entry->getPlatform()) { switch ($entry->getPlatform()) {
case self::MADE_BY_MS_DOS: case self::MADE_BY_MS_DOS:
// no break
/** @noinspection PhpMissingBreakStatementInspection */
case self::MADE_BY_WINDOWS_NTFS: case self::MADE_BY_WINDOWS_NTFS:
if ($entry->getPlatform() != self::MADE_BY_MS_DOS || if ($entry->getPlatform() != self::MADE_BY_MS_DOS ||
($xattr & 0700) != ($xattr & 0700) !=

View File

@@ -446,6 +446,7 @@ class ZipInputStream implements ZipInputStreamInterface
if (!extension_loaded('bz2')) { if (!extension_loaded('bz2')) {
throw new ZipException('Extension bzip2 not install'); throw new ZipException('Extension bzip2 not install');
} }
/** @noinspection PhpComposerExtensionStubsInspection */
$content = bzdecompress($content); $content = bzdecompress($content);
break; break;
default: default:
@@ -552,7 +553,7 @@ class ZipInputStream implements ZipInputStreamInterface
// skip source extraLength from input stream // skip source extraLength from input stream
fseek($this->in, $sourceExtraLength, SEEK_CUR); fseek($this->in, $sourceExtraLength, SEEK_CUR);
} else { } else {
$copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;; $copyInToOutLength += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $sourceExtraLength + $nameLength;
} }
if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) { if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) {
// crc-32 4 bytes // crc-32 4 bytes

View File

@@ -255,6 +255,7 @@ class ZipOutputStream implements ZipOutputStreamInterface
$compressionLevel = $entry->getCompressionLevel() === ZipFileInterface::LEVEL_DEFAULT_COMPRESSION ? $compressionLevel = $entry->getCompressionLevel() === ZipFileInterface::LEVEL_DEFAULT_COMPRESSION ?
ZipEntry::LEVEL_DEFAULT_BZIP2_COMPRESSION : ZipEntry::LEVEL_DEFAULT_BZIP2_COMPRESSION :
$entry->getCompressionLevel(); $entry->getCompressionLevel();
/** @noinspection PhpComposerExtensionStubsInspection */
$entryContent = bzcompress($entryContent, $compressionLevel); $entryContent = bzcompress($entryContent, $compressionLevel);
if (is_int($entryContent)) { if (is_int($entryContent)) {
throw new ZipException('Error bzip2 compress. Error code: ' . $entryContent); throw new ZipException('Error bzip2 compress. Error code: ' . $entryContent);

View File

@@ -26,9 +26,11 @@ class CryptoUtil
throw new \RuntimeException("Could not generate a random string."); throw new \RuntimeException("Could not generate a random string.");
} }
} elseif (function_exists('openssl_random_pseudo_bytes')) { } elseif (function_exists('openssl_random_pseudo_bytes')) {
/** @noinspection PhpComposerExtensionStubsInspection */
return openssl_random_pseudo_bytes($length); return openssl_random_pseudo_bytes($length);
} elseif (function_exists('mcrypt_create_iv')) { } elseif (function_exists('mcrypt_create_iv')) {
/** @noinspection PhpDeprecationInspection */ /** @noinspection PhpDeprecationInspection */
/** @noinspection PhpComposerExtensionStubsInspection */
return mcrypt_create_iv($length); return mcrypt_create_iv($length);
} else { } else {
throw new RuntimeException('Extension openssl or mcrypt not loaded'); throw new RuntimeException('Extension openssl or mcrypt not loaded');

View File

@@ -423,6 +423,7 @@ class ZipFile implements ZipFileInterface
if ($compressionMethod === null) { if ($compressionMethod === null) {
if (function_exists('mime_content_type')) { if (function_exists('mime_content_type')) {
/** @noinspection PhpComposerExtensionStubsInspection */
$mimeType = @mime_content_type($filename); $mimeType = @mime_content_type($filename);
$type = strtok($mimeType, '/'); $type = strtok($mimeType, '/');
if ($type === 'image') { if ($type === 'image') {
@@ -611,8 +612,7 @@ class ZipFile implements ZipFileInterface
\Iterator $iterator, \Iterator $iterator,
$localPath = '/', $localPath = '/',
$compressionMethod = null $compressionMethod = null
) ) {
{
$localPath = (string)$localPath; $localPath = (string)$localPath;
if (strlen($localPath) !== 0) { if (strlen($localPath) !== 0) {
$localPath = trim($localPath, '\\/'); $localPath = trim($localPath, '\\/');
@@ -696,8 +696,7 @@ class ZipFile implements ZipFileInterface
$localPath = '/', $localPath = '/',
$recursive = true, $recursive = true,
$compressionMethod = null $compressionMethod = null
) ) {
{
$inputDir = (string)$inputDir; $inputDir = (string)$inputDir;
if (strlen($inputDir) === 0) { if (strlen($inputDir) === 0) {
throw new InvalidArgumentException('Input dir empty'); throw new InvalidArgumentException('Input dir empty');
@@ -793,8 +792,7 @@ class ZipFile implements ZipFileInterface
$localPath = "/", $localPath = "/",
$recursive = true, $recursive = true,
$compressionMethod = null $compressionMethod = null
) ) {
{
$regexPattern = (string)$regexPattern; $regexPattern = (string)$regexPattern;
if (empty($regexPattern)) { if (empty($regexPattern)) {
throw new InvalidArgumentException("regex pattern empty"); throw new InvalidArgumentException("regex pattern empty");

View File

@@ -33,6 +33,7 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testOpenFileCantOpen() public function testOpenFileCantOpen()
{ {
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) { if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges'); $this->markTestSkipped('Skip the test for a user with root privileges');
} }
@@ -152,6 +153,7 @@ class ZipFileTest extends ZipTestCase
if (!extension_loaded("gd")) { if (!extension_loaded("gd")) {
$this->markTestSkipped('not extension gd'); $this->markTestSkipped('not extension gd');
} }
/** @noinspection PhpComposerExtensionStubsInspection */
$zipFile->openFromStream(imagecreate(1, 1)); $zipFile->openFromStream(imagecreate(1, 1));
} }
@@ -1057,6 +1059,7 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testExtractFail3() public function testExtractFail3()
{ {
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) { if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges'); $this->markTestSkipped('Skip the test for a user with root privileges');
} }
@@ -1275,6 +1278,7 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testAddFileCantOpen() public function testAddFileCantOpen()
{ {
/** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) { if (posix_getuid() === 0) {
$this->markTestSkipped('Skip the test for a user with root privileges'); $this->markTestSkipped('Skip the test for a user with root privileges');
} }
@@ -1588,6 +1592,7 @@ class ZipFileTest extends ZipTestCase
*/ */
public function testSaveAsFileNotWritable() public function testSaveAsFileNotWritable()
{ {
/** @noinspection PhpComposerExtensionStubsInspection */
if (0 === posix_getuid()) { if (0 === posix_getuid()) {
$this->markTestSkipped('Skip the test for a user with root privileges'); $this->markTestSkipped('Skip the test for a user with root privileges');
} }