ZIPの規格
from Compression Streams APIでzipを実装する
ZIPの規格
ZIPの仕様を日本語でまとめる · GitHub
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
最新の規格書
さすがに最初にこれを読むのはきつい
ほかの解説を読んでだいたいの構造を知ってから、この仕様書で正確な定義を知るのがいいと思う
2024-08-21 読めるようになったtakker.icon
過去のversionへのリンクリスト
ZIP書庫ファイル フォーマット - 略して仮。
The structure of a PKZip file
メモリ配置の図解を見たいときに参照するとよい
zipファイルの構造を少しだけ理解する | Chanomic Blog
ZIP_(ファイルフォーマット) - Wikipedia
https://en.wikipedia.org/wiki/ZIP_(file_format)#Compression_methods
ISOではISO/IEC 21320-1:2015で規格化されている
2024-08-21 fflateを題材にしながら規格を読み進めている
https://github.com/takker99/deno-zip/tree/fflate-study/fflate
だいぶ理解できた
https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html#general
table:general structure
local file descriptor N個
Archive decryption header 0~1個 only v6.2 or greater
Archive extra data record 0~1個 only v6.2 or greater
Central directory 1個
Archive decryption headerとArchive extra data recordはCentral Directory Encryption Featureに使われる
Local file descriptor
table: Local file descriptor
Local file header 1個
File data 1個
Data descriptor 0~1個
https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html#localheader
Local file header 64B
table:Local file header
offset in byte
0 signature 0x50
1 0x4b
2 0x03
3 0x04
4 Version
5
6 Flags
7
8 Comression method
9
10 Modified time standard MS-DOS format
11
12 Modified date standard MS-DOS format
13
14 CRC-32 checksum
15
16
17
18 Comressed size
19
20
21
22 Uncompressed size
23
24
25
26 Filename length
27
28 Extra field length
29
30 Filename
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 Extra filed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Version
6.2なら0x3E00と格納される
62=16*3+14*1=3E
→little endianで0x3E00
table:Flags
offset in bits
0 encrypted file
1 compression option
2 compression option
3 data descriptor
4 enhanced deflation
5 compressed patched data
6 strong encryption
7 unused
8 unused
9 unused
10 unused
11 language encoding
12 reserved
13 masc header values
14 reserved
15 reserved
CRC-32 checksumはCRC-32 algorithmで計算する
magic numberは0xdebb20e3(little endian)
data descriptorがtrueなら、Local file headerのCRC-32 checksum, Compressssed size, Uncompressed sizeは0になる
table:Compression method
value (little endian)
0x0000 no compression
0x0100 shrunk
0x0200 reduced with compression factor 1
0x0300 reduced with compression factor 2
0x0400 reduced with compression factor 3
0x0500 reduced with compression factor 4
0x0600 imploded
0x0700 reserved
0x0800 deflated
0x0900 enhanced deflated
0x0a00 PKWare DCL imploded
0x0b00 reserved
0x0c00 compressed using BZIP2
0x0d00 reserved
0x0e00 LZMA
0x0f00 reserved
0x1000 reserved
0x1100 reserved
0x1200 compressed using IBM TERSE
0x1300 IBM LZ77 z
0x6200 PPMd version I, Rev 1
Data descriptor 16B
https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html#datadescriptor
Local file headerのFlagsのbit 3が立っているときのみ存在
table:Data descriptor
offset in bytes
0 CRC-32 checksum
1 Compressed size
2
3
4
5
6
7
8 Uncompressed size
9
10
11
Archive extra data record 32B
https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html#archivedecrypt
Central directory
https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html#centraldirectory
table:Central directory
Central directory file header N個
Zip64 end of central directory record 0~1個
Zip64 end of central directory locator 0~1個
End of central directory record 1個
Central directory file header 80B
Local file headerに追加情報を加えたもの
End of central directory record 32B
table:End of central directory record
offset in bytes
0 Signature 0x50
1 0x4b
2 0x05
3 0x06
4 Disk Number
5
6 Disk # w/cd
7
8 Disk entries
9
10 Total entries
11
12 Central directory size
13
14
15
16 Offset of cd wrt to starting disk
17
18
19
20 Comment length
21
22 ZIP file comment
23
24
25
26
27
28
29
30
31
directoryの取り扱い
https://bombrary.github.io/blog/posts/zip-format-report/#おまけディレクトリの取り扱い
/で終わる空のファイルとして扱われるようだ
directory配下にあるファイルは、ファイルパスがfilenameとして格納される
ZIP File Format Specification
#2024-08-31 18:16:36
#2024-08-21 16:09:49
#2024-08-20 20:43:05
#2024-07-08 09:47:31
#2024-07-07 16:53:14
#2024-02-05 14:58:50
#2024-02-03 11:22:52