ZIP Archive (.zip)

PKWARE ZIP container with per-file compression.

Overview

A ZIP file is a sequence of local file headers and data, followed by a central directory and an end-of-central-directory record (PK 05 06). Each member has its own compression method (store, Deflate, Deflate64, bzip2, LZMA, Zstandard, XZ, PPMd and legacy Shrink/Reduce/Implode), CRC-32 and optional encryption (ZipCrypto or WinZip AES). ZIP64 extensions lift the 4 GiB and 65,535-entry limits, and archives can be split into volumes.

Where it is used

  • General file exchange; the container for Office Open XML, ODF, JAR, APK and EPUB files.
  • Software distribution and backups.

History

  • Created by Phil Katz at PKWARE in 1989; the APPNOTE specification is maintained by PKWARE.
  • ZIP64 was added in 2001.

Status today

  • Universal; supported natively by Windows, macOS and Linux tools.

Structures read by the implementation

Offsets are in bytes from the start of the buffer named in each heading. Field names are taken from the implementation and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

CentralEntry.TryRead buffer h · ZipArchiveReader.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x82u16 LEFlags
0xA2u16 LEEthod
0xC2u16 LEDos Time
0xE2u16 LEDos Date
0x104u32 LECrc32
0x144u32 LECompressed
0x184u32 LEUncompressed
0x1C2u16 LEName Length
0x1E2u16 LEExtra Length
0x202u16 LEComment Length
0x222u16 LEDisk Start
0x264u32 LEExternal Attributes
0x2A4u32 LEHeader Offset

CentralEntry.TryRead buffer z64 · ZipArchiveReader.cs

OffsetSizeTypeFieldNotes
p8u64 LEUncompressed
p8u64 LECompressed
p8u64 LEHeader Offset

ZipArchiveReader.ReadCore buffer e · ZipArchiveReader.cs

OffsetSizeTypeFieldNotes
0x02u16 LE–
0x42u16 LEDisk
0x62u16 LECd Disk
0xA2u16 LETotal
0xC4u32 LECd Size
0x104u32 LECd Offset
0x142u16 LEComment Length

struct.TrySignedDescriptor buffer d · ZipArchiveReader.cs

OffsetSizeTypeFieldNotes
0x44u32 LECrc
0x84u32 LE–
0x88u64 LE–
0xC4u32 LE–
0x108u64 LE–

struct.TryUnsignedDescriptor buffer d · ZipArchiveReader.cs

OffsetSizeTypeFieldNotes
0x04u32 LEShort32
0x04u32 LELong64
0x44u32 LE–
0x48u64 LE–
0x84u32 LEShort32
0xC8u64 LELong64

ZipExtraFields.TryFind buffer extra · ZipFormat.cs

OffsetSizeTypeFieldNotes
(pos + 2)2u16 LESize
pos2u16 LEField Id

ZipLocalHeader.TryRead buffer h · ZipFormat.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x42u16 LEVersion Needed
0x62u16 LEFlags
0x82u16 LEMethod
0xA2u16 LEDos Time
0xC2u16 LEDos Date
0xE4u32 LECrc32
0x124u32 LECompressed
0x164u32 LEUncompressed
0x1A2u16 LEName Length
0x1C2u16 LEExtra Length

ZipLocalHeader.TryRead buffer z64 · ZipFormat.cs

OffsetSizeTypeFieldNotes
p8u64 LEUncompressed
p8u64 LECompressed

ZipText.UnicodePathFromExtra buffer field · ZipFormat.cs

OffsetSizeTypeFieldNotes
0x01u8–
0x14u32 LEName Crc

Other fields read

Read inOffsetSizeTypeFieldNotes
ZipByteReader.TryReadUInt320x04u32 LEValue
ZipByteReader.TryReadUInt640x08u64 LEValue

Constants

General ZipArchiveReader

NameValueTypeNotes
FirstSearchChunk64 * 1024int

—- Apple iWork ——————————————————————– DocumentProperties

NameValueTypeNotes
MaxIndexZipSize512 * 1024 * 1024int

General ZipEntryDataStream

NameValueTypeNotes
SectorErrorMarker.PatternLengthint

General ZipSignatures

NameValueTypeNotes
LocalFileHeader0x04034B50uintPK 03 04
DataDescriptor0x08074B50uintPK 07 08
CentralDirectory0x02014B50uintPK 01 02
DigitalSignature0x05054B50uintPK 05 05
Zip64EndOfCentralDir0x06064B50uintPK 06 06
Zip64Locator0x07064B50uintPK 06 07
EndOfCentralDir0x06054B50uintPK 05 06
ArchiveExtraData0x08064B50uintPK 06 08 (central directory encryption)
LocalHeaderSize30int
CentralHeaderSize46int
EndOfCentralDirSize22int
Zip64LocatorSize20int
Zip64EndOfCentralDirMinSize56int
Zip64ExtraId0x0001ushort
UnicodePathExtraId0x7075ushortInfo-ZIP Unicode Path
FlagEncrypted0x0001ushort
FlagDataDescriptor0x0008ushort
FlagStrongEncryption0x0040ushort
FlagUtf80x0800ushort

General ZipCrc32

NameValueTypeNotes
TableBuildTable()uint[]

General ZipText

NameValueTypeNotes
Utf8new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false)Encoding

General ZipMethods

NameValueTypeNotes
Stored0ushort
Deflated8ushort
Aes99ushort

—————————————————————— Shrink (method 1) Bits

NameValueTypeNotes
Free-1, Root = -2, Max = 8192int

Encrypted entries: find the password once (known keys, then a prompt), checked by fully decrypting and decoding the smallest encrypted file against its CRC (or WinZip AES HMAC). ZipArchiveModule

NameValueTypeNotes
SupportedMethods[0, 1, 2, 3, 4, 5, 6, 8, 9, 12, 14, 20, 93, 95, 98]int[]

Implementation limits reader

ClassNameValueNotes
ZipArchiveReaderMaxFirstNameLength4096
ZipArchiveReaderMaxPropertiesSize1 << 20
ZipArchiveReaderMaxPropertyLength120
ZipArchiveReaderMaxSearchChunk1 << 20
ZipCarverMaxNamesInDetails25
ZipEntryDataStreamBufferSize256 * 1024multiple of the marker pattern length
ZipByteReaderWindowSize64 * 1024
ZipByteReaderWindowAlign4096

ZipEntryStatus enum

NameValue
NotChecked(next)
Ok(next)
CrcMismatch(next)
SizeMismatch(next)
DecompressionFailed(next)
Truncated(next)
DataMissing(next)
Encrypted(next)
UnsupportedMethod(next)
Directory(next)
SkippedLimit(next)

Signatures and magic strings referenced

TextWhereContext
PKstruct.FindDataDescriptorint index = span[from..].IndexOf(“PK”u8);
Structures and constants were extracted from: Carving/Plugins/Zip/ZipArchiveInfo.cs, Carving/Plugins/Zip/ZipArchiveReader.cs, Carving/Plugins/Zip/ZipCarver.cs, Carving/Plugins/Zip/ZipEntryDataStream.cs, Carving/Plugins/Zip/ZipFormat.cs, Carving/Plugins/Zip/ZipLegacy.cs, Carving/Plugins/Zip/ZipParts.cs, Modules/FileSystems/ZipArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.