1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-07-13 20:26:18 +02:00

fixed for php 32-bit

This commit is contained in:
Ne-Lexa
2019-12-06 12:09:37 +03:00
parent e03c963dc1
commit e2c058840c
21 changed files with 117 additions and 154 deletions

View File

@ -1028,7 +1028,7 @@ $rules = [
* Adds a default `@coversNothing` annotation to PHPUnit test * Adds a default `@coversNothing` annotation to PHPUnit test
* classes that have no `@covers*` annotation. * classes that have no `@covers*` annotation.
*/ */
'php_unit_test_class_requires_covers' => true, 'php_unit_test_class_requires_covers' => false,
// PHPDoc should contain `@param` for all params. // PHPDoc should contain `@param` for all params.
'phpdoc_add_missing_param_annotation' => [ 'phpdoc_add_missing_param_annotation' => [

View File

@ -25,8 +25,13 @@
"ext-zlib": "*", "ext-zlib": "*",
"psr/http-message": "^1.0" "psr/http-message": "^1.0"
}, },
"config": {
"platform": {
"php": "5.5"
}
},
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.8|~5.7", "phpunit/phpunit": "^4.8|^5.7",
"zendframework/zend-diactoros": "^1.4" "zendframework/zend-diactoros": "^1.4"
}, },
"autoload": { "autoload": {

View File

@ -2,6 +2,7 @@
namespace PhpZip\Crypto; namespace PhpZip\Crypto;
use PhpZip\Exception\RuntimeException;
use PhpZip\Exception\ZipAuthenticationException; use PhpZip\Exception\ZipAuthenticationException;
use PhpZip\Exception\ZipCryptoException; use PhpZip\Exception\ZipCryptoException;
use PhpZip\Model\ZipEntry; use PhpZip\Model\ZipEntry;
@ -324,7 +325,7 @@ class TraditionalPkwareEncryptionEngine implements ZipEncryptionEngine
/** /**
* Update keys. * Update keys.
* *
* @param string $charAt * @param int $charAt
*/ */
private function updateKeys($charAt) private function updateKeys($charAt)
{ {
@ -356,6 +357,10 @@ class TraditionalPkwareEncryptionEngine implements ZipEncryptionEngine
*/ */
public function decrypt($content) public function decrypt($content)
{ {
if (\PHP_INT_SIZE === 4) {
throw new RuntimeException('Traditional PKWARE Encryption is not supported in 32-bit PHP.');
}
$password = $this->entry->getPassword(); $password = $this->entry->getPassword();
$this->initKeys($password); $this->initKeys($password);
@ -418,6 +423,10 @@ class TraditionalPkwareEncryptionEngine implements ZipEncryptionEngine
*/ */
public function encrypt($data) public function encrypt($data)
{ {
if (\PHP_INT_SIZE === 4) {
throw new RuntimeException('Traditional PKWARE Encryption is not supported in 32-bit PHP.');
}
$crc = $this->entry->isDataDescriptorRequired() ? $crc = $this->entry->isDataDescriptorRequired() ?
($this->entry->getDosTime() & 0x0000ffff) << 16 : ($this->entry->getDosTime() & 0x0000ffff) << 16 :
$this->entry->getCrc(); $this->entry->getCrc();

View File

@ -49,9 +49,9 @@ class WinZipAesEngine implements ZipEncryptionEngine
* *
* @param string $content Input stream buffer * @param string $content Input stream buffer
* *
* @throws ZipAuthenticationException
* @throws ZipCryptoException * @throws ZipCryptoException
* @throws ZipException * @throws ZipException
* @throws ZipAuthenticationException
* *
* @return string * @return string
*/ */
@ -100,8 +100,10 @@ class WinZipAesEngine implements ZipEncryptionEngine
} }
$password = $this->entry->getPassword(); $password = $this->entry->getPassword();
\assert($password !== null);
\assert($keyStrengthBits >= self::AES_BLOCK_SIZE_BITS); if ($password === null) {
throw new ZipException(sprintf('Password not set for entry %s', $this->entry->getName()));
}
/** /**
* WinZip 99-character limit. * WinZip 99-character limit.

View File

@ -102,27 +102,21 @@ class Zip64ExtraField implements ExtraField
throw new RuntimeException('entry is null'); throw new RuntimeException('entry is null');
} }
$off = 0; $off = 0;
// Read in Uncompressed Size.
$size = $this->entry->getSize();
if ($size >= 0xffffffff) { // Read in Uncompressed Size.
\assert($size === 0xffffffff); if ($this->entry->getSize() === 0xffffffff) {
$this->entry->setSize(PackUtil::unpackLongLE(substr($data, $off, 8))); $this->entry->setSize(PackUtil::unpackLongLE(substr($data, $off, 8)));
$off += 8; $off += 8;
} }
// Read in Compressed Size.
$compressedSize = $this->entry->getCompressedSize();
if ($compressedSize >= 0xffffffff) { // Read in Compressed Size.
\assert($compressedSize === 0xffffffff); if ($this->entry->getCompressedSize() === 0xffffffff) {
$this->entry->setCompressedSize(PackUtil::unpackLongLE(substr($data, $off, 8))); $this->entry->setCompressedSize(PackUtil::unpackLongLE(substr($data, $off, 8)));
$off += 8; $off += 8;
} }
// Read in Relative Header Offset.
$offset = $this->entry->getOffset();
if ($offset >= 0xffffffff) { // Read in Relative Header Offset.
\assert(0xffffffff, $offset); if ($this->entry->getOffset() === 0xffffffff) {
$this->entry->setOffset(PackUtil::unpackLongLE(substr($data, $off, 8))); $this->entry->setOffset(PackUtil::unpackLongLE(substr($data, $off, 8)));
} }
} }

View File

@ -22,29 +22,26 @@ use PhpZip\ZipFileInterface;
*/ */
abstract class ZipAbstractEntry implements ZipEntry abstract class ZipAbstractEntry implements ZipEntry
{ {
/** @var int bit flags for init state */
private $init;
/** @var string Entry name (filename in archive) */ /** @var string Entry name (filename in archive) */
private $name; private $name;
/** @var int Made by platform */ /** @var int Made by platform */
private $platform; private $platform = self::UNKNOWN;
/** @var int */ /** @var int */
private $versionNeededToExtract = 20; private $versionNeededToExtract = 20;
/** @var int Compression method */ /** @var int Compression method */
private $method; private $method = self::UNKNOWN;
/** @var int */ /** @var int */
private $general; private $general = 0;
/** @var int Dos time */ /** @var int Dos time */
private $dosTime; private $dosTime = self::UNKNOWN;
/** @var int Crc32 */ /** @var int Crc32 */
private $crc; private $crc = self::UNKNOWN;
/** @var int Compressed size */ /** @var int Compressed size */
private $compressedSize = self::UNKNOWN; private $compressedSize = self::UNKNOWN;
@ -53,7 +50,7 @@ abstract class ZipAbstractEntry implements ZipEntry
private $size = self::UNKNOWN; private $size = self::UNKNOWN;
/** @var int External attributes */ /** @var int External attributes */
private $externalAttributes; private $externalAttributes = 0;
/** @var int relative Offset Of Local File Header */ /** @var int relative Offset Of Local File Header */
private $offset = self::UNKNOWN; private $offset = self::UNKNOWN;
@ -67,7 +64,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
private $extraFieldsCollection; private $extraFieldsCollection;
/** @var string comment field */ /** @var string|null comment field */
private $comment; private $comment;
/** @var string entry password for read or write encryption data */ /** @var string entry password for read or write encryption data */
@ -150,6 +147,7 @@ abstract class ZipAbstractEntry implements ZipEntry
} }
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true); $this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
$this->name = $name; $this->name = $name;
$this->externalAttributes = $this->isDirectory() ? 0x10 : 0;
return $this; return $this;
} }
@ -174,11 +172,11 @@ abstract class ZipAbstractEntry implements ZipEntry
} }
/** /**
* @return int Get platform * @return int platform
*/ */
public function getPlatform() public function getPlatform()
{ {
return $this->isInit(self::BIT_PLATFORM) ? $this->platform & 0xffff : self::UNKNOWN; return $this->platform;
} }
/** /**
@ -192,44 +190,18 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setPlatform($platform) public function setPlatform($platform)
{ {
$known = $platform !== self::UNKNOWN; if ($platform !== self::UNKNOWN) {
if ($known) {
if ($platform < 0x00 || $platform > 0xff) { if ($platform < 0x00 || $platform > 0xff) {
throw new ZipException('Platform out of range'); throw new ZipException('Platform out of range');
} }
$this->platform = $platform; $this->platform = $platform;
} else { } else {
$this->platform = 0; $this->platform = 0; // ms-dos
} }
$this->setInit(self::BIT_PLATFORM, $known);
return $this; return $this;
} }
/**
* @param int $mask
*
* @return bool
*/
protected function isInit($mask)
{
return ($this->init & $mask) !== 0;
}
/**
* @param int $mask
* @param bool $init
*/
protected function setInit($mask, $init)
{
if ($init) {
$this->init |= $mask;
} else {
$this->init &= ~$mask;
}
}
/** /**
* Version needed to extract. * Version needed to extract.
* *
@ -450,11 +422,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function getMethod() public function getMethod()
{ {
$isInit = $this->isInit(self::BIT_METHOD); return $this->method;
return $isInit ?
$this->method & 0xffff :
self::UNKNOWN;
} }
/** /**
@ -470,7 +438,6 @@ abstract class ZipAbstractEntry implements ZipEntry
{ {
if ($method === self::UNKNOWN) { if ($method === self::UNKNOWN) {
$this->method = $method; $this->method = $method;
$this->setInit(self::BIT_METHOD, false);
return $this; return $this;
} }
@ -484,7 +451,6 @@ abstract class ZipAbstractEntry implements ZipEntry
case ZipFileInterface::METHOD_DEFLATED: case ZipFileInterface::METHOD_DEFLATED:
case ZipFileInterface::METHOD_BZIP2: case ZipFileInterface::METHOD_BZIP2:
$this->method = $method; $this->method = $method;
$this->setInit(self::BIT_METHOD, true);
break; break;
default: default:
@ -501,7 +467,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function getTime() public function getTime()
{ {
if (!$this->isInit(self::BIT_DATE_TIME)) { if ($this->getDosTime() === self::UNKNOWN) {
return self::UNKNOWN; return self::UNKNOWN;
} }
@ -533,7 +499,6 @@ abstract class ZipAbstractEntry implements ZipEntry
throw new ZipException('DosTime out of range'); throw new ZipException('DosTime out of range');
} }
$this->dosTime = $dosTime; $this->dosTime = $dosTime;
$this->setInit(self::BIT_DATE_TIME, true);
} }
/** /**
@ -554,7 +519,6 @@ abstract class ZipAbstractEntry implements ZipEntry
} else { } else {
$this->dosTime = 0; $this->dosTime = 0;
} }
$this->setInit(self::BIT_DATE_TIME, $known);
return $this; return $this;
} }
@ -566,10 +530,6 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function getExternalAttributes() public function getExternalAttributes()
{ {
if (!$this->isInit(self::BIT_EXTERNAL_ATTR)) {
return $this->isDirectory() ? 0x10 : 0;
}
return $this->externalAttributes; return $this->externalAttributes;
} }
@ -582,14 +542,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setExternalAttributes($externalAttributes) public function setExternalAttributes($externalAttributes)
{ {
$known = $externalAttributes !== self::UNKNOWN; $this->externalAttributes = $externalAttributes;
if ($known) {
$this->externalAttributes = $externalAttributes;
} else {
$this->externalAttributes = 0;
}
$this->setInit(self::BIT_EXTERNAL_ATTR, $known);
return $this; return $this;
} }
@ -655,7 +608,7 @@ abstract class ZipAbstractEntry implements ZipEntry
/** /**
* Set entry comment. * Set entry comment.
* *
* @param $comment * @param string|null $comment
* *
* @throws ZipException * @throws ZipException
* *
@ -669,8 +622,8 @@ abstract class ZipAbstractEntry implements ZipEntry
if ($commentLength < 0x0000 || $commentLength > 0xffff) { if ($commentLength < 0x0000 || $commentLength > 0xffff) {
throw new ZipException('Comment too long'); throw new ZipException('Comment too long');
} }
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
} }
$this->setGeneralPurposeBitFlag(self::GPBF_UTF8, true);
$this->comment = $comment; $this->comment = $comment;
return $this; return $this;
@ -703,8 +656,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setCrc($crc) public function setCrc($crc)
{ {
$this->crc = $crc; $this->crc = (int) $crc;
$this->setInit(self::BIT_CRC, true);
return $this; return $this;
} }

View File

@ -17,14 +17,6 @@ use PhpZip\ZipFileInterface;
interface ZipEntry interface ZipEntry
{ {
// Bit masks for initialized fields. // Bit masks for initialized fields.
const BIT_PLATFORM = 1;
const BIT_METHOD = 2;
const BIT_CRC = 4;
const BIT_DATE_TIME = 64;
const BIT_EXTERNAL_ATTR = 128; const BIT_EXTERNAL_ATTR = 128;
/** The unknown value for numeric properties. */ /** The unknown value for numeric properties. */
@ -48,13 +40,12 @@ interface ZipEntry
/** General Purpose Bit Flag mask for encrypted data. */ /** General Purpose Bit Flag mask for encrypted data. */
const GPBF_ENCRYPTED = 1; const GPBF_ENCRYPTED = 1;
// 1 << 0 // (For Methods 8 and 9 - Deflating)
// (For Methods 8 and 9 - Deflating) // Bit 2 Bit 1
// Bit 2 Bit 1 // 0 0 Normal compression
// 0 0 Normal compression // 0 1 Maximum compression
// 0 1 Maximum compression // 1 0 Fast compression
// 1 0 Fast compression // 1 1 Super Fast compression
// 1 1 Super Fast compression
const GPBF_COMPRESSION_FLAG1 = 2; // 1 << 1 const GPBF_COMPRESSION_FLAG1 = 2; // 1 << 1
const GPBF_COMPRESSION_FLAG2 = 4; // 1 << 2 const GPBF_COMPRESSION_FLAG2 = 4; // 1 << 2

View File

@ -234,12 +234,8 @@ class ZipInfo
$this->name = $entry->getName(); $this->name = $entry->getName();
$this->folder = $entry->isDirectory(); $this->folder = $entry->isDirectory();
$this->size = \PHP_INT_SIZE === 4 ? $this->size = $entry->getSize();
sprintf('%u', $entry->getSize()) : $this->compressedSize = $entry->getCompressedSize();
$entry->getSize();
$this->compressedSize = \PHP_INT_SIZE === 4 ?
sprintf('%u', $entry->getCompressedSize()) :
$entry->getCompressedSize();
$this->mtime = $mtime; $this->mtime = $mtime;
$this->ctime = $ctime; $this->ctime = $ctime;
$this->atime = $atime; $this->atime = $atime;
@ -255,16 +251,13 @@ class ZipInfo
$attributes = str_repeat(' ', 12); $attributes = str_repeat(' ', 12);
$externalAttributes = $entry->getExternalAttributes(); $externalAttributes = $entry->getExternalAttributes();
$externalAttributes = \PHP_INT_SIZE === 4 ?
sprintf('%u', $externalAttributes) :
$externalAttributes;
$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:
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 & self::UNX_IRWXU) !==
(0400 | (self::UNX_IRUSR |
(!($externalAttributes & 1) << 7) | (!($externalAttributes & 1) << 7) |
(($externalAttributes & 0x10) << 2)) (($externalAttributes & 0x10) << 2))
) { ) {
@ -392,30 +385,29 @@ class ZipInfo
{ {
$return = ''; $return = '';
$compressionMethod = $entry->getMethod();
if ($entry->isEncrypted()) { if ($entry->isEncrypted()) {
if ($entry->getMethod() === ZipEntry::METHOD_WINZIP_AES) { if ($entry->getMethod() === ZipEntry::METHOD_WINZIP_AES) {
$return = ucfirst(self::$valuesCompressionMethod[$entry->getMethod()]); $return .= ucfirst(self::$valuesCompressionMethod[$entry->getMethod()]);
/** @var WinZipAesEntryExtraField|null $field */ /** @var WinZipAesEntryExtraField|null $field */
$field = $entry->getExtraFieldsCollection()->get(WinZipAesEntryExtraField::getHeaderId()); $field = $entry->getExtraFieldsCollection()->get(WinZipAesEntryExtraField::getHeaderId());
if ($field !== null) { if ($field !== null) {
$return .= '-' . $field->getKeyStrength(); $return .= '-' . $field->getKeyStrength();
$compressionMethod = $field->getMethod();
if (isset(self::$valuesCompressionMethod[$field->getMethod()])) {
$return .= ' ' . ucfirst(self::$valuesCompressionMethod[$field->getMethod()]);
}
} }
} else { } else {
$return .= 'ZipCrypto'; $return .= 'ZipCrypto';
if (isset(self::$valuesCompressionMethod[$entry->getMethod()])) {
$return .= ' ' . ucfirst(self::$valuesCompressionMethod[$entry->getMethod()]);
}
} }
} elseif (isset(self::$valuesCompressionMethod[$entry->getMethod()])) {
$return = ucfirst(self::$valuesCompressionMethod[$entry->getMethod()]); $return .= ' ';
}
if (isset(self::$valuesCompressionMethod[$compressionMethod])) {
$return .= ucfirst(self::$valuesCompressionMethod[$compressionMethod]);
} else { } else {
$return = 'unknown'; $return .= 'unknown';
} }
return $return; return $return;

View File

@ -277,7 +277,6 @@ class ZipInputStream implements ZipInputStreamInterface
// Extra Field may have been parsed, map it to the real // Extra Field may have been parsed, map it to the real
// offset and conditionally update the preamble size from it. // offset and conditionally update the preamble size from it.
$lfhOff = $this->mapper->map($entry->getOffset()); $lfhOff = $this->mapper->map($entry->getOffset());
$lfhOff = \PHP_INT_SIZE === 4 ? sprintf('%u', $lfhOff) : $lfhOff;
if ($lfhOff < $this->preamble) { if ($lfhOff < $this->preamble) {
$this->preamble = $lfhOff; $this->preamble = $lfhOff;
@ -412,9 +411,6 @@ class ZipInputStream implements ZipInputStreamInterface
} }
$pos = $entry->getOffset(); $pos = $entry->getOffset();
$pos = \PHP_INT_SIZE === 4
? sprintf('%u', $pos) // PHP 32-Bit
: $pos; // PHP 64-Bit
$startPos = $pos = $this->mapper->map($pos); $startPos = $pos = $this->mapper->map($pos);
fseek($this->in, $startPos); fseek($this->in, $startPos);
@ -429,7 +425,9 @@ class ZipInputStream implements ZipInputStreamInterface
$data = unpack('vfileLength/vextraLength', fread($this->in, 4)); $data = unpack('vfileLength/vextraLength', fread($this->in, 4));
$pos += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $data['fileLength'] + $data['extraLength']; $pos += ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $data['fileLength'] + $data['extraLength'];
\assert($entry->getCrc() !== ZipEntry::UNKNOWN); if ($entry->getCrc() === ZipEntry::UNKNOWN) {
throw new ZipException(sprintf('Missing crc for entry %s', $entry->getName()));
}
$method = $entry->getMethod(); $method = $entry->getMethod();
@ -437,7 +435,6 @@ class ZipInputStream implements ZipInputStreamInterface
// Get raw entry content // Get raw entry content
$compressedSize = $entry->getCompressedSize(); $compressedSize = $entry->getCompressedSize();
$compressedSize = \PHP_INT_SIZE === 4 ? sprintf('%u', $compressedSize) : $compressedSize;
$content = ''; $content = '';
if ($compressedSize > 0) { if ($compressedSize > 0) {
@ -587,8 +584,11 @@ class ZipInputStream implements ZipInputStreamInterface
public function copyEntry(ZipEntry $entry, ZipOutputStreamInterface $out) public function copyEntry(ZipEntry $entry, ZipOutputStreamInterface $out)
{ {
$pos = $entry->getOffset(); $pos = $entry->getOffset();
\assert($pos !== ZipEntry::UNKNOWN);
$pos = \PHP_INT_SIZE === 4 ? sprintf('%u', $pos) : $pos; if ($pos === ZipEntry::UNKNOWN) {
throw new ZipException(sprintf('Missing local header offset for entry %s', $entry->getName()));
}
$pos = $this->mapper->map($pos); $pos = $this->mapper->map($pos);
$nameLength = \strlen($entry->getName()); $nameLength = \strlen($entry->getName());
@ -688,7 +688,6 @@ class ZipInputStream implements ZipInputStreamInterface
public function copyEntryData(ZipEntry $entry, ZipOutputStreamInterface $out) public function copyEntryData(ZipEntry $entry, ZipOutputStreamInterface $out)
{ {
$offset = $entry->getOffset(); $offset = $entry->getOffset();
$offset = \PHP_INT_SIZE === 4 ? sprintf('%u', $offset) : $offset;
$offset = $this->mapper->map($offset); $offset = $this->mapper->map($offset);
$nameLength = \strlen($entry->getName()); $nameLength = \strlen($entry->getName());

View File

@ -179,8 +179,17 @@ class ZipOutputStream implements ZipOutputStreamInterface
fwrite($this->out, $entryContent); fwrite($this->out, $entryContent);
} }
\assert($entry->getCrc() !== ZipEntry::UNKNOWN); if ($entry->getCrc() === ZipEntry::UNKNOWN) {
\assert($entry->getSize() !== ZipEntry::UNKNOWN); throw new ZipException(sprintf('No crc for entry %s', $entry->getName()));
}
if ($entry->getSize() === ZipEntry::UNKNOWN) {
throw new ZipException(sprintf('No uncompressed size for entry %s', $entry->getName()));
}
if ($entry->getCompressedSize() === ZipEntry::UNKNOWN) {
throw new ZipException(sprintf('No compressed size for entry %s', $entry->getName()));
}
if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) { if ($entry->getGeneralPurposeBitFlag(ZipEntry::GPBF_DATA_DESCRIPTOR)) {
// data descriptor signature 4 bytes (0x08074b50) // data descriptor signature 4 bytes (0x08074b50)
@ -226,7 +235,7 @@ class ZipOutputStream implements ZipOutputStreamInterface
$utf8 = true; $utf8 = true;
if ($encrypted && $entry->getPassword() === null) { if ($encrypted && $entry->getPassword() === null) {
throw new ZipException('Can not password from entry ' . $entry->getName()); throw new ZipException(sprintf('Password not set for entry %s', $entry->getName()));
} }
// Compose General Purpose Bit Flag. // Compose General Purpose Bit Flag.

View File

@ -9,7 +9,6 @@ use PhpZip\Util\CryptoUtil;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class Issue24Test extends ZipTestCase class Issue24Test extends ZipTestCase
{ {

View File

@ -3,6 +3,7 @@
namespace PhpZip; namespace PhpZip;
use PhpZip\Exception\Crc32Exception; use PhpZip\Exception\Crc32Exception;
use PhpZip\Exception\RuntimeException;
use PhpZip\Exception\ZipAuthenticationException; use PhpZip\Exception\ZipAuthenticationException;
use PhpZip\Exception\ZipException; use PhpZip\Exception\ZipException;
@ -12,7 +13,6 @@ use PhpZip\Exception\ZipException;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class PhpZipExtResourceTest extends ZipTestCase class PhpZipExtResourceTest extends ZipTestCase
{ {
@ -126,7 +126,14 @@ class PhpZipExtResourceTest extends ZipTestCase
*/ */
public function testBug70752() public function testBug70752()
{ {
$this->setExpectedException(ZipAuthenticationException::class, 'nvalid password for zip entry "bug70752.txt"'); if (\PHP_INT_SIZE === 4) { // php 32 bit
$this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
} else { // php 64 bit
$this->setExpectedException(
ZipAuthenticationException::class,
'nvalid password for zip entry "bug70752.txt"'
);
}
$filename = __DIR__ . '/php-zip-ext-test-resources/bug70752.zip'; $filename = __DIR__ . '/php-zip-ext-test-resources/bug70752.zip';

View File

@ -8,7 +8,6 @@ use PhpZip\Exception\ZipException;
* @internal * @internal
* *
* @large * @large
* @covers
*/ */
class Zip64Test extends ZipTestCase class Zip64Test extends ZipTestCase
{ {

View File

@ -11,7 +11,6 @@ use PhpZip\Util\CryptoUtil;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipAlignTest extends ZipTestCase class ZipAlignTest extends ZipTestCase
{ {

View File

@ -8,7 +8,6 @@ use PhpZip\Exception\ZipException;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipEventTest extends ZipTestCase class ZipEventTest extends ZipTestCase
{ {

View File

@ -12,7 +12,6 @@ use PhpZip\Util\Iterator\IgnoreFilesRecursiveFilterIterator;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipFileAddDirTest extends ZipTestCase class ZipFileAddDirTest extends ZipTestCase
{ {

View File

@ -19,7 +19,6 @@ use Zend\Diactoros\Response;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipFileTest extends ZipTestCase class ZipFileTest extends ZipTestCase
{ {
@ -44,6 +43,8 @@ class ZipFileTest extends ZipTestCase
/** @noinspection PhpComposerExtensionStubsInspection */ /** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) { if (posix_getuid() === 0) {
static::markTestSkipped('Skip the test for a user with root privileges'); static::markTestSkipped('Skip the test for a user with root privileges');
return;
} }
static::assertNotFalse(file_put_contents($this->outputFilename, 'content')); static::assertNotFalse(file_put_contents($this->outputFilename, 'content'));
@ -170,6 +171,8 @@ class ZipFileTest extends ZipTestCase
if (!\extension_loaded('gd')) { if (!\extension_loaded('gd')) {
static::markTestSkipped('not extension gd'); static::markTestSkipped('not extension gd');
return;
} }
/** @noinspection PhpComposerExtensionStubsInspection */ /** @noinspection PhpComposerExtensionStubsInspection */
$zipFile->openFromStream(imagecreate(1, 1)); $zipFile->openFromStream(imagecreate(1, 1));
@ -425,6 +428,8 @@ class ZipFileTest extends ZipTestCase
{ {
if (!\function_exists('mime_content_type')) { if (!\function_exists('mime_content_type')) {
static::markTestSkipped('Function mime_content_type not exists'); static::markTestSkipped('Function mime_content_type not exists');
return;
} }
$outputFilename = $this->outputFilename; $outputFilename = $this->outputFilename;
$this->outputFilename .= '.gif'; $this->outputFilename .= '.gif';
@ -1117,6 +1122,8 @@ class ZipFileTest extends ZipTestCase
/** @noinspection PhpComposerExtensionStubsInspection */ /** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) { if (posix_getuid() === 0) {
static::markTestSkipped('Skip the test for a user with root privileges'); static::markTestSkipped('Skip the test for a user with root privileges');
return;
} }
$zipFile = new ZipFile(); $zipFile = new ZipFile();
@ -1341,6 +1348,8 @@ class ZipFileTest extends ZipTestCase
/** @noinspection PhpComposerExtensionStubsInspection */ /** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) { if (posix_getuid() === 0) {
static::markTestSkipped('Skip the test for a user with root privileges'); static::markTestSkipped('Skip the test for a user with root privileges');
return;
} }
static::assertNotFalse(file_put_contents($this->outputFilename, '')); static::assertNotFalse(file_put_contents($this->outputFilename, ''));
@ -1658,6 +1667,8 @@ class ZipFileTest extends ZipTestCase
/** @noinspection PhpComposerExtensionStubsInspection */ /** @noinspection PhpComposerExtensionStubsInspection */
if (posix_getuid() === 0) { if (posix_getuid() === 0) {
static::markTestSkipped('Skip the test for a user with root privileges'); static::markTestSkipped('Skip the test for a user with root privileges');
return;
} }
static::assertTrue(mkdir($this->outputDirname, 0444, true)); static::assertTrue(mkdir($this->outputDirname, 0444, true));

View File

@ -11,7 +11,6 @@ use PhpZip\Util\CryptoUtil;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipMatcherTest extends TestCase class ZipMatcherTest extends TestCase
{ {

View File

@ -2,6 +2,7 @@
namespace PhpZip; namespace PhpZip;
use PhpZip\Exception\RuntimeException;
use PhpZip\Exception\ZipAuthenticationException; use PhpZip\Exception\ZipAuthenticationException;
use PhpZip\Exception\ZipEntryNotFoundException; use PhpZip\Exception\ZipEntryNotFoundException;
use PhpZip\Exception\ZipException; use PhpZip\Exception\ZipException;
@ -14,7 +15,6 @@ use PhpZip\Util\CryptoUtil;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipPasswordTest extends ZipFileAddDirTest class ZipPasswordTest extends ZipFileAddDirTest
{ {
@ -25,8 +25,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
*/ */
public function testSetPassword() public function testSetPassword()
{ {
if (\PHP_INT_SIZE === 4) { if (\PHP_INT_SIZE === 4) { // php 32 bit
static::markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); $this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
} }
$password = base64_encode(CryptoUtil::randomBytes(100)); $password = base64_encode(CryptoUtil::randomBytes(100));
@ -120,8 +120,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
*/ */
public function testTraditionalEncryption() public function testTraditionalEncryption()
{ {
if (\PHP_INT_SIZE === 4) { if (\PHP_INT_SIZE === 4) { // php 32 bit
static::markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); $this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
} }
$password = base64_encode(CryptoUtil::randomBytes(50)); $password = base64_encode(CryptoUtil::randomBytes(50));
@ -200,8 +200,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
*/ */
public function testEncryptionEntries() public function testEncryptionEntries()
{ {
if (\PHP_INT_SIZE === 4) { if (\PHP_INT_SIZE === 4) { // php 32 bit
static::markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); $this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
} }
$password1 = '353442434235424234'; $password1 = '353442434235424234';
@ -247,8 +247,8 @@ class ZipPasswordTest extends ZipFileAddDirTest
*/ */
public function testEncryptionEntriesWithDefaultPassword() public function testEncryptionEntriesWithDefaultPassword()
{ {
if (\PHP_INT_SIZE === 4) { if (\PHP_INT_SIZE === 4) { // php 32 bit
static::markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); $this->setExpectedException(RuntimeException::class, 'Traditional PKWARE Encryption is not supported in 32-bit PHP.');
} }
$password1 = '353442434235424234'; $password1 = '353442434235424234';

View File

@ -10,7 +10,6 @@ use PhpZip\Exception\ZipException;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipRemoteFileTest extends ZipTestCase class ZipRemoteFileTest extends ZipTestCase
{ {

View File

@ -11,7 +11,6 @@ namespace PhpZip;
* @internal * @internal
* *
* @small * @small
* @covers
*/ */
class ZipSlipVulnerabilityTest extends ZipTestCase class ZipSlipVulnerabilityTest extends ZipTestCase
{ {