bypassflow/rules-archive-zip は、ZIPアーカイブとZIPコンテナ形式のファイルを検証するルール拡張パッケージです。
- PHP 8.5 以上
- ext-zip
bypassflow/rules
composer require bypassflow/rules-archive-zip<?php
use bypassflow\RulesArchiveZip\Rule\FileHeader\StrictZipFileHeaderPath;
$path = '/path/to/document.docx';
$rule = new StrictZipFileHeaderPath(extension: 'docx');
if (!$rule->validate($path)) {
$failure = $rule->failureDescriptor();
}bypassflow\RulesArchiveZip\Rule\FileHeader\ZipFileHeaderData- バイナリデータのZIPファイルヘッダを検証します。
bypassflow\RulesArchiveZip\Rule\FileHeader\ZipFileHeaderPath- ファイルパスからZIPファイルヘッダを検証します。
bypassflow\RulesArchiveZip\Rule\FileHeader\StrictZipFileHeaderData- バイナリデータのZIPファイルヘッダに加え、
docx、xlsx、pptx、odtの代表エントリを検証します。
- バイナリデータのZIPファイルヘッダに加え、
bypassflow\RulesArchiveZip\Rule\FileHeader\StrictZipFileHeaderPath- ファイルパスからZIPファイルヘッダとZIPコンテナ構造を検証します。
bypassflow\RulesArchiveZip\Rule\Archive\Zip\ZipArchiveEntryCount- ZIPアーカイブのエントリ数を検証します。
bypassflow\RulesArchiveZip\Rule\Archive\Zip\ZipArchiveExpandedSize- ZIPアーカイブの展開後サイズを検証します。
bypassflow\RulesArchiveZip\Rule\Archive\Zip\Security\ZipArchivePathTraversalSafe../などを含む危険なエントリ名を拒否します。
現時点ではありません。
各ルールは検証に失敗した場合に false を返します。失敗理由は failureDescriptor() から取得できます。
<?php
$rule = new StrictZipFileHeaderPath(extension: 'docx');
if (!$rule->validate('/path/to/file.zip')) {
$descriptor = $rule->failureDescriptor();
$code = $descriptor->code;
}