file in abyss
フォーマット一覧へ戻る

Archive

ZIP ZIP Archive

複数ファイルを格納するアーカイブ形式。DOCX/XLSX/APK/JAR/EPUBなど多くの形式のコンテナでもあります。

Extensions .zip
MIME application/zip

マジックナンバー

ファイルを解析
オフセット 0 Local file header
50 4B 03 04
PK..
オフセット 0 Empty archive end record
50 4B 05 06
PK..
オフセット 0 Spanned archive marker
50 4B 07 08
PK..

構造

  1. Local file headers
  2. Compressed file data
  3. Central directory
  4. End of central directory

注意点

  • ZIPシグネチャだけではDOCXやAPKなどの派生形式を区別できません。
  • 自己解凍形式では先頭が実行ファイルになる場合があります。

判定コード例

SIGNATURE = bytes.fromhex("504b0304")
OFFSET = 0

def is_zip(path: str) -> bool:
    with open(path, "rb") as f:
        f.seek(OFFSET)
        head = f.read(len(SIGNATURE))
    return head == SIGNATURE

実践的な使い方

ユースケース

ZIP Archive は圧縮、展開、バックアップ、添付、複数ファイルの検査に使われます。展開前にパス・ファイル数・圧縮後/展開後サイズを検証してください。

よくある判定ミス

  • .zip という拡張子だけではファイルの中身を保証できません。アップロードや変換の処理では、拡張子・MIMEタイプ・先頭バイト・形式固有の構造チェックを組み合わせるべきです。
  • ZIP Archive は 50 4B 03 04 または 50 4B 05 06 または 50 4B 07 08 のようなシグネチャで始まりますが、関連するコンテナや破損ファイルでは追加の検証が必要になる場合があります。

セキュリティ上の注意

アーカイブには zip-slip パス、過剰な展開、隠しファイル、二重拡張子が含まれることがあります。展開パスを正規化し、ファイル数とサイズの上限を設けてください。

サンプルの活用

11 個のサンプルで、先頭バイト判定・パーサのエラー・アップロード上限・ダウンロード挙動をテストできます。

サンプルファイル

11 / 11 files
Sample Traits Size Source / license / SHA-256
Arc

Single-file ZIP

Single-file ZIP is a ZIP Archive sample generated for file format testing. It can be used to test downloads, parsers, previews, and file type detection.

single-file.zip
Type Sample
Small file
130 B
Generated CC0 1.0
SHA-256 bdd0e789d32b3d771dda6614fe1c43ae23da8c5490d1f603b0f76c03aa66d10f
Download
Arc

Empty ZIP

Empty ZIP is a ZIP Archive sample generated for file format testing. It can be used to test downloads, parsers, previews, and file type detection.

empty.zip
Type Sample
Small file
22 B
Generated CC0 1.0
SHA-256 8739c76e681f900923b900c9df0ef75cf421d39cabb54650c4b9ad19b6a76d85
Download
Arc

Two File ZIP

Two File ZIP is a ZIP Archive sample generated for file format testing. It can be used to test downloads, parsers, previews, and file type detection.

two-files.zip
Type Sample
Small file
264 B
Generated CC0 1.0
SHA-256 5147699c1713b7d5d9d32bc88baf5fe5d82f7cd33305e70ff885be3c7e91c827
Download
Arc

Blue Sky ZIP

Blue Sky ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

01-blue-sky.zip
Type Sample
Small file
675 B
SHA-256 406899035ac2a5ebd7641aaf09b0026caf34ae6414f224801a2df79888baab21
Download
Arc

Flower Garden ZIP

Flower Garden ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

02-flower-garden.zip
Type Sample
1.2 KB
SHA-256 9ff8454befd465893ed4f21427fb53aff3b830d7501e125445d32b27e6d71477
Download
Arc

Navy Blue Sky ZIP

Navy Blue Sky ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

03-navy-blue-sky.zip
Type Sample
1.6 KB
SHA-256 821a889e4ca078ef99efa381eaf06128e7859bf439ee3eb53f099eea43af5b13
Download
Arc

Nature of the Sky ZIP

Nature of the Sky ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

04-nature-sky.zip
Type Sample
2.1 KB
SHA-256 4b7eef406dfa9120a46e419abf15f8d5fdd4b59f82e41548e895b3859d1c81ee
Download
Arc

Sky Landscape ZIP

Sky Landscape ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

05-sky-landscape.zip
Type Sample
2.9 KB
SHA-256 1efa3a18f71d6235167237cdc8611dbacd9812b6aac86d5fdac2e87843a0a96f
Download
Arc

Starry Sky ZIP

Starry Sky ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

06-starry-sky.zip
Type Sample
2.9 KB
SHA-256 9dea35b1174a734275f911257297b00a3f7269459b6f99becfc061f3e4cfeed1
Download
Arc

Blue Night Sky ZIP

Blue Night Sky ZIP is a ZIP Archive sample based on Wikimedia Commons. It can be used to test downloads, parsers, previews, and file type detection.

07-blue-night-sky.zip
Type Sample
3.7 KB
SHA-256 ae59106122a39caf2142ab9cb6947522d55b5afeba9d8d89fa63d5801fcb752b
Download
Arc

NASA Blue Marble ZIP

NASA Blue Marble ZIP is a ZIP Archive sample based on NASA Image and Video Library. It can be used to test downloads, parsers, previews, and file type detection.

nasa-blue-marble-2012-east.zip
Type Sample
10 KB
SHA-256 527dd0ee5ce84bfea705fa242f5a9bd38c951d91f9c2c37f79ab8766612530db
Download

よくある質問

ZIP Archive のマジックナンバー(ファイルシグネチャ)は?

ZIP Archive ファイルはバイトシグネチャ 50 4B 03 04 ("PK..") または 50 4B 05 06 ("PK..") または 50 4B 07 08 ("PK..") で始まります。拡張子に頼らず、この先頭バイトを読み取って形式を判定してください。

ZIP Archive のMIMEタイプは?

ZIP Archive のMIMEタイプは application/zip です。

ZIP Archive の拡張子は?

ZIP Archive ファイルは .zip 拡張子を使います。拡張子は慣習にすぎず中身を保証しないため、シグネチャや構造のチェックと組み合わせてください。

関連フォーマット