From 0d4b10151075d005e6cef98363d28bdef7a25ea9 Mon Sep 17 00:00:00 2001 From: Ne-Lexa Date: Tue, 14 Nov 2017 11:28:02 +0300 Subject: [PATCH] Skipped some tests for php 32-bit platform. --- README.RU.md | 4 ++++ README.md | 4 ++++ src/PhpZip/Util/PackUtil.php | 8 +++++--- tests/PhpZip/ZipPasswordTest.php | 11 +++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.RU.md b/README.RU.md index af686f8..a0e8a4f 100644 --- a/README.RU.md +++ b/README.RU.md @@ -50,6 +50,10 @@ - Поддержка `ZIP64` (размер файла более 4 GB или количество записей в архиве более 65535). - Встроенная поддержка выравнивания архива для оптимизации Android пакетов (APK) [`zipalign`](https://developer.android.com/studio/command-line/zipalign.html). - Работа с паролями для PHP 5.5 +> **Внимание!** +> +> Для 32-bit систем, в данный момент не поддерживается метод шифрование `Traditional PKWARE Encryption (ZipCrypto)`. +> Используйте метод шифрования `WinZIP AES Encryption`, когда это возможно. + Установка пароля для чтения архива глобально или для некоторых записей. + Изменение пароля архива, в том числе и для отдельных записей. + Удаление пароля архива глобально или для отдельных записей. diff --git a/README.md b/README.md index d2430da..22ca737 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ Table of contents - Support for `ZIP64` (file size is more than 4 GB or the number of entries in the archive is more than 65535). - Built-in support for aligning the archive to optimize Android packages (APK) [`zipalign`](https://developer.android.com/studio/command-line/zipalign.html). - Working with passwords for PHP 5.5 +> **Attention!** +> +> For 32-bit systems, the `Traditional PKWARE Encryption (ZipCrypto)` encryption method is not currently supported. +> Use the encryption method `WinZIP AES Encryption`, whenever possible. + Set the password to read the archive for all entries or only for some. + Change the password for the archive, including for individual entries. + Delete the archive password for all or individual entries. diff --git a/src/PhpZip/Util/PackUtil.php b/src/PhpZip/Util/PackUtil.php index 79ca6a3..c622360 100644 --- a/src/PhpZip/Util/PackUtil.php +++ b/src/PhpZip/Util/PackUtil.php @@ -54,9 +54,11 @@ class PackUtil */ public static function toSignedInt32($int) { - $int = $int & 0xffffffff; - if (PHP_INT_SIZE === 8 && ($int & 0x80000000)) { - return $int - 0x100000000; + if (PHP_INT_SIZE === 8) { + $int = $int & 0xffffffff; + if ($int & 0x80000000) { + return $int - 0x100000000; + } } return $int; } diff --git a/tests/PhpZip/ZipPasswordTest.php b/tests/PhpZip/ZipPasswordTest.php index 014b6b6..379788e 100644 --- a/tests/PhpZip/ZipPasswordTest.php +++ b/tests/PhpZip/ZipPasswordTest.php @@ -6,6 +6,9 @@ use PhpZip\Exception\ZipAuthenticationException; use PhpZip\Model\ZipInfo; use PhpZip\Util\CryptoUtil; +/** + * Tests with zip password. + */ class ZipPasswordTest extends ZipFileAddDirTest { /** @@ -13,6 +16,10 @@ class ZipPasswordTest extends ZipFileAddDirTest */ public function testSetPassword() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); + } + $password = base64_encode(CryptoUtil::randomBytes(100)); $badPassword = "sdgt43r23wefe"; @@ -96,6 +103,10 @@ class ZipPasswordTest extends ZipFileAddDirTest public function testTraditionalEncryption() { + if (PHP_INT_SIZE === 4) { + $this->markTestSkipped('Skip test for 32-bit system. Not support Traditional PKWARE Encryption.'); + } + $password = base64_encode(CryptoUtil::randomBytes(50)); $zip = new ZipFile();