Skip to content

bypassflow/rules-archive-zip

Repository files navigation

bypassflow/rules-archive-zip

bypassflow/rules-archive-zip は、ZIPアーカイブとZIPコンテナ形式のファイルを検証するルール拡張パッケージです。

Requirements

  • PHP 8.5 以上
  • ext-zip
  • bypassflow/rules

Installation

composer require bypassflow/rules-archive-zip

Quick Start

<?php

use bypassflow\RulesArchiveZip\Rule\FileHeader\StrictZipFileHeaderPath;

$path = '/path/to/document.docx';
$rule = new StrictZipFileHeaderPath(extension: 'docx');

if (!$rule->validate($path)) {
    $failure = $rule->failureDescriptor();
}

主要 API

  • bypassflow\RulesArchiveZip\Rule\FileHeader\ZipFileHeaderData
    • バイナリデータのZIPファイルヘッダを検証します。
  • bypassflow\RulesArchiveZip\Rule\FileHeader\ZipFileHeaderPath
    • ファイルパスからZIPファイルヘッダを検証します。
  • bypassflow\RulesArchiveZip\Rule\FileHeader\StrictZipFileHeaderData
    • バイナリデータのZIPファイルヘッダに加え、docxxlsxpptxodtの代表エントリを検証します。
  • 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
    • ../などを含む危険なエントリ名を拒否します。

functions/helper

現時点ではありません。

失敗時の扱い

各ルールは検証に失敗した場合に false を返します。失敗理由は failureDescriptor() から取得できます。

<?php

$rule = new StrictZipFileHeaderPath(extension: 'docx');

if (!$rule->validate('/path/to/file.zip')) {
    $descriptor = $rule->failureDescriptor();
    $code = $descriptor->code;
}

About

ZIPアーカイブとZIPコンテナ形式を検証するルール拡張を提供します。

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages