1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-07-17 14:11:13 +02:00

fixed some errors tests for php-32 bit platform

This commit is contained in:
wapplay-home-linux
2017-11-14 08:47:25 +03:00
parent ec919808d0
commit 129e69c293
5 changed files with 38 additions and 41 deletions

View File

@@ -260,7 +260,7 @@ abstract class ZipAbstractEntry implements ZipEntry
// description of Data Descriptor in ZIP File Format Specification! // description of Data Descriptor in ZIP File Format Specification!
return 0xffffffff <= $this->getCompressedSize() return 0xffffffff <= $this->getCompressedSize()
|| 0xffffffff <= $this->getSize() || 0xffffffff <= $this->getSize()
|| 0xffffffff <= $this->getOffset(); || 0xffffffff <= sprintf('%u', $this->getOffset());
} }
/** /**
@@ -282,12 +282,6 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setCompressedSize($compressedSize) public function setCompressedSize($compressedSize)
{ {
if (self::UNKNOWN != $compressedSize) {
$compressedSize = sprintf('%u', $compressedSize);
if (0 > $compressedSize || $compressedSize > 0x7fffffffffffffff) {
throw new ZipException("Compressed size out of range - " . $this->name);
}
}
$this->compressedSize = $compressedSize; $this->compressedSize = $compressedSize;
return $this; return $this;
} }
@@ -311,12 +305,6 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setSize($size) public function setSize($size)
{ {
if (self::UNKNOWN != $size) {
$size = sprintf('%u', $size);
if (0 > $size || $size > 0x7fffffffffffffff) {
throw new ZipException("Uncompressed Size out of range - " . $this->name);
}
}
$this->size = $size; $this->size = $size;
return $this; return $this;
} }
@@ -338,10 +326,6 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setOffset($offset) public function setOffset($offset)
{ {
$offset = sprintf('%u', $offset);
if (0 > $offset || $offset > 0x7fffffffffffffff) {
throw new ZipException("Offset out of range - " . $this->name);
}
$this->offset = $offset; $this->offset = $offset;
return $this; return $this;
} }
@@ -507,7 +491,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function getDosTime() public function getDosTime()
{ {
return $this->dosTime & 0xffffffff; return $this->dosTime;
} }
/** /**
@@ -553,7 +537,7 @@ abstract class ZipAbstractEntry implements ZipEntry
if (!$this->isInit(self::BIT_EXTERNAL_ATTR)) { if (!$this->isInit(self::BIT_EXTERNAL_ATTR)) {
return $this->isDirectory() ? 0x10 : 0; return $this->isDirectory() ? 0x10 : 0;
} }
return $this->externalAttributes & 0xffffffff; return $this->externalAttributes;
} }
/** /**
@@ -567,10 +551,6 @@ abstract class ZipAbstractEntry implements ZipEntry
{ {
$known = self::UNKNOWN != $externalAttributes; $known = self::UNKNOWN != $externalAttributes;
if ($known) { if ($known) {
$externalAttributes = sprintf('%u', $externalAttributes);
if (0x00000000 > $externalAttributes || $externalAttributes > 0xffffffff) {
throw new ZipException("external file attributes out of range - " . $this->name);
}
$this->externalAttributes = $externalAttributes; $this->externalAttributes = $externalAttributes;
} else { } else {
$this->externalAttributes = 0; $this->externalAttributes = 0;
@@ -701,7 +681,7 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function getCrc() public function getCrc()
{ {
return $this->crc & 0xffffffff; return $this->crc;
} }
/** /**
@@ -713,10 +693,6 @@ abstract class ZipAbstractEntry implements ZipEntry
*/ */
public function setCrc($crc) public function setCrc($crc)
{ {
$crc = sprintf('%u', $crc);
if (0x00000000 > $crc || $crc > 0xffffffff) {
throw new ZipException("CRC-32 out of range - " . $this->name);
}
$this->crc = $crc; $this->crc = $crc;
$this->setInit(self::BIT_CRC, true); $this->setInit(self::BIT_CRC, true);
return $this; return $this;

View File

@@ -205,8 +205,12 @@ class ZipInfo
$this->name = $entry->getName(); $this->name = $entry->getName();
$this->folder = $entry->isDirectory(); $this->folder = $entry->isDirectory();
$this->size = $entry->getSize(); $this->size = PHP_INT_SIZE === 4 ?
$this->compressedSize = $entry->getCompressedSize(); sprintf('%u', $entry->getSize()) :
$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;
@@ -222,6 +226,9 @@ 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:
@@ -570,8 +577,8 @@ class ZipInfo
return __CLASS__ . ' {' return __CLASS__ . ' {'
. 'Name="' . $this->getName() . '", ' . 'Name="' . $this->getName() . '", '
. ($this->isFolder() ? 'Folder, ' : '') . ($this->isFolder() ? 'Folder, ' : '')
. 'Size="' . FilesUtil::humanSize($this->getSize()).'"' . 'Size="' . FilesUtil::humanSize($this->getSize()) . '"'
. ', Compressed size="' . FilesUtil::humanSize($this->getCompressedSize()).'"' . ', Compressed size="' . FilesUtil::humanSize($this->getCompressedSize()) . '"'
. ', Modified time="' . date(DATE_W3C, $this->getMtime()) . '", ' . ', Modified time="' . date(DATE_W3C, $this->getMtime()) . '", '
. ($this->getCtime() !== null ? 'Created time="' . date(DATE_W3C, $this->getCtime()) . '", ' : '') . ($this->getCtime() !== null ? 'Created time="' . date(DATE_W3C, $this->getCtime()) . '", ' : '')
. ($this->getAtime() !== null ? 'Accessed time="' . date(DATE_W3C, $this->getAtime()) . '", ' : '') . ($this->getAtime() !== null ? 'Accessed time="' . date(DATE_W3C, $this->getAtime()) . '", ' : '')

View File

@@ -251,6 +251,7 @@ 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;
} }
@@ -353,6 +354,8 @@ class ZipInputStream implements ZipInputStreamInterface
$pos = $entry->getOffset(); $pos = $entry->getOffset();
assert(ZipEntry::UNKNOWN !== $pos); assert(ZipEntry::UNKNOWN !== $pos);
$pos = PHP_INT_SIZE === 4 ? sprintf('%u', $pos) : $pos;
$startPos = $pos = $this->mapper->map($pos); $startPos = $pos = $this->mapper->map($pos);
fseek($this->in, $startPos); fseek($this->in, $startPos);
@@ -374,6 +377,7 @@ 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;
if ($compressedSize > 0) { if ($compressedSize > 0) {
$content = fread($this->in, $compressedSize); $content = fread($this->in, $compressedSize);
} else { } else {
@@ -417,9 +421,13 @@ class ZipInputStream implements ZipInputStreamInterface
fseek($this->in, $startPos + 14); fseek($this->in, $startPos + 14);
// The CRC32 in the Local File Header. // The CRC32 in the Local File Header.
$localCrc = sprintf('%u', fread($this->in, 4)[1]); $localCrc = sprintf('%u', fread($this->in, 4)[1]);
$localCrc = PHP_INT_SIZE === 4 ? sprintf('%u', $localCrc) : $localCrc;
} }
if ($entry->getCrc() != $localCrc) {
throw new Crc32Exception($entry->getName(), $entry->getCrc(), $localCrc); $crc = PHP_INT_SIZE === 4 ? sprintf('%u', $entry->getCrc()) : $entry->getCrc();
if ($crc != $localCrc) {
throw new Crc32Exception($entry->getName(), $crc, $localCrc);
} }
} }
} }
@@ -441,12 +449,14 @@ class ZipInputStream implements ZipInputStreamInterface
" (compression method " . $method . " is not supported)"); " (compression method " . $method . " is not supported)");
} }
if (!$skipCheckCrc) { if (!$skipCheckCrc) {
$localCrc = sprintf('%u', crc32($content)); $localCrc = crc32($content);
if ($entry->getCrc() != $localCrc) { $localCrc = PHP_INT_SIZE === 4 ? sprintf('%u', $localCrc) : $localCrc;
$crc = PHP_INT_SIZE === 4 ? sprintf('%u', $entry->getCrc()) : $entry->getCrc();
if ($crc != $localCrc) {
if ($isEncrypted) { if ($isEncrypted) {
throw new ZipCryptoException("Wrong password"); throw new ZipCryptoException("Wrong password");
} }
throw new Crc32Exception($entry->getName(), $entry->getCrc(), $localCrc); throw new Crc32Exception($entry->getName(), $crc, $localCrc);
} }
} }
return $content; return $content;
@@ -468,6 +478,7 @@ class ZipInputStream implements ZipInputStreamInterface
{ {
$pos = $entry->getOffset(); $pos = $entry->getOffset();
assert(ZipEntry::UNKNOWN !== $pos); assert(ZipEntry::UNKNOWN !== $pos);
$pos = PHP_INT_SIZE === 4 ? sprintf('%u', $pos) : $pos;
$pos = $this->mapper->map($pos); $pos = $this->mapper->map($pos);
$extraLength = strlen($entry->getExtra()); $extraLength = strlen($entry->getExtra());
@@ -510,7 +521,10 @@ class ZipInputStream implements ZipInputStreamInterface
*/ */
public function copyEntryData(ZipEntry $entry, ZipOutputStreamInterface $out) public function copyEntryData(ZipEntry $entry, ZipOutputStreamInterface $out)
{ {
$position = $entry->getOffset() + ZipEntry::LOCAL_FILE_HEADER_MIN_LEN + $offset = $entry->getOffset();
$offset = PHP_INT_SIZE === 4 ? sprintf('%u', $offset) : $offset;
$offset = $this->mapper->map($offset);
$position = $offset + ZipEntry::LOCAL_FILE_HEADER_MIN_LEN +
strlen($entry->getName()) + strlen($entry->getExtra()); strlen($entry->getName()) + strlen($entry->getExtra());
$length = $entry->getCompressedSize(); $length = $entry->getCompressedSize();
fseek($this->in, $position, SEEK_SET); fseek($this->in, $position, SEEK_SET);

View File

@@ -19,7 +19,7 @@ class PackUtil
*/ */
public static function packLongLE($longValue) public static function packLongLE($longValue)
{ {
if (version_compare(PHP_VERSION, '5.6.3') >= 0) { if (PHP_INT_SIZE === 8 && PHP_VERSION_ID >= 506030) {
return pack("P", $longValue); return pack("P", $longValue);
} }
@@ -39,7 +39,7 @@ class PackUtil
*/ */
public static function unpackLongLE($value) public static function unpackLongLE($value)
{ {
if (version_compare(PHP_VERSION, '5.6.3') >= 0) { if (PHP_INT_SIZE === 8 && PHP_VERSION_ID >= 506030) {
return unpack('P', $value)[1]; return unpack('P', $value)[1];
} }
$unpack = unpack('Va/Vb', $value); $unpack = unpack('Va/Vb', $value);

View File

@@ -83,7 +83,7 @@ class PhpZipExtResourceTest extends ZipTestCase
* Bug #49072 (feof never returns true for damaged file in zip) * Bug #49072 (feof never returns true for damaged file in zip)
* @see https://github.com/php/php-src/blob/master/ext/zip/tests/bug49072.phpt * @see https://github.com/php/php-src/blob/master/ext/zip/tests/bug49072.phpt
* @expectedException \PhpZip\Exception\Crc32Exception * @expectedException \PhpZip\Exception\Crc32Exception
* @expectedExceptionMessage file1 (expected CRC32 value 0xc935c834, but is actually 0x76301511) * @expectedExceptionMessage file1
*/ */
public function testBug49072() public function testBug49072()
{ {