7z Archive (.7z)

7-Zip archive format with LZMA compression.

Overview

A 7z file starts with a signature header (7z BC AF 27 1C, version, start-header CRC, next-header offset, size and CRC). A header at the end describes folders, each a graph of coders (LZMA, LZMA2, PPMd, BZip2, Deflate, Copy and filters such as BCJ and Delta) with unpack sizes and CRCs. AES-256 encryption can cover data and headers.

Where it is used

  • High-ratio compression and software distribution.
  • Backups and large downloads.

History

  • Created by Igor Pavlov, first released with 7-Zip in 1999.

Status today

  • Actively maintained; the format is open and documented in the LZMA SDK.

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.

SevenZipCarver.Carve buffer start · SevenZipCarver.cs

OffsetSizeTypeFieldNotes
0x06bytes–
0x61u8–
0x84u32 LEStart Crc
0xC8u64 LENext Offset
0xC20bytes–
0x148u64 LENext Size
0x1C4u32 LENext Crc

Other fields read

Read inOffsetSizeTypeFieldNotes
SevenZipArchiveModule.FindSfxArchivep + 1220bytes–

Constants

General Bcj2

NameValueTypeNotes
NumBitModelTotalBits11int
BitModelTotal1u << NumBitModelTotalBitsuint
NumMoveBits5int
TopValue1u << 24uint

General LzmaDecoder

NameValueTypeNotes
NumStates12int
NumPosBitsMax4int
NumLenToPosStates4int
NumAlignBits4int
StartPosModelIndex4int
EndPosModelIndex14int
NumFullDistances1 << (EndPosModelIndex >> 1)int
MatchMinLen2int
ProbInit1 << 10ushort

General RangeDecoder

NameValueTypeNotes
TopValue1u << 24uint

General Ppmd7zRangeDecoder

NameValueTypeNotes
TopValue1u << 24uint

General Ppmd7

NameValueTypeNotes
UnitSize12int
IntBits7int
PeriodBits7int
BinScale1 << (IntBits + PeriodBits)int
NumIndexes4 + 4 + 4 + 26int
ExpEscape[25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2]byte[]
InitBinEsc[0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051]ushort[]
Indx2Unitsnew byte[NumIndexes]byte[]
Units2Indxnew byte[128]byte[]
NS2Indxnew byte[256]byte[]
NS2BSIndxnew byte[256]byte[]
HB2Flagnew byte[256]byte[]

General Ppmd8

NameValueTypeNotes
UnitSize12int
IntBits7int
PeriodBits7int
BinScale1 << (IntBits + PeriodBits)int
NumIndexes4 + 4 + 4 + 26int
EmptyNode0xFFFFFFFFuint
RestoreRestart0, RestoreCutOff = 1int
ExpEscape[25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2]byte[]
InitBinEsc[0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051]ushort[]
Indx2Unitsnew byte[NumIndexes]byte[]
Units2Indxnew byte[128]byte[]
NS2Indxnew byte[260]byte[]
NS2BSIndxnew byte[256]byte[]

General Ppmd8RangeDecoder

NameValueTypeNotes
Top1u << 24, Bot = 1u << 15uint

General SevenZipCarver

NameValueTypeNotes
StartHeaderSize32int
Signature[(byte)’7′, (byte)’z’, 0xBC, 0xAF, 0x27, 0x1C]byte[]

Property ids (7zFormat.txt) SevenZipHeaderReader

NameValueTypeNotes
MethodCopy[0x00]byte[]
MethodLzma[0x03, 0x01, 0x01]byte[]
MethodLzma2[0x21]byte[]
MethodAes[0x06, 0xF1, 0x07, 0x01]byte[]

General SevenZipExtractor

NameValueTypeNotes
StartHeaderSize32int
Signature[0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C]byte[]

General SevenZipArchiveModule

NameValueTypeNotes
Magic[0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C]byte[]

Implementation limits reader

ClassNameValueNotes
Ppmd7MaxOrder64
Ppmd7MaxFreq124
Ppmd8MinOrder2
Ppmd8MaxOrder16
Ppmd8MaxFreq124
SevenZipCarverMaxHeaderSize64L * 1024 * 1024
SevenZipCarverMaxNamesInDetails25
SevenZipHeaderReaderMaxNesting4
SevenZipHeaderReaderMaxDecodedHeaderSize256L * 1024 * 1024
SevenZipHeaderReaderMaxFiles10_000_000
SevenZipExtractorMaxNesting4
SevenZipExtractorMaxDecodedHeaderSize256L * 1024 * 1024
SevenZipExtractorMaxFolderOutputint.MaxValuein-memory decode budget per folder (byte[]-bounded)
SevenZipExtractorMaxFiles10_000_000
SevenZipArchiveModuleSfxScanLimit8 * 1024 * 1024

BranchFilter enum

NameValue
X86(next)
PowerPc(next)
Ia64(next)
Arm(next)
ArmThumb(next)
Sparc(next)
Arm64(next)
RiscV(next)
Structures and constants were extracted from: Carving/Plugins/SevenZip/Bcj2.cs, Carving/Plugins/SevenZip/BranchFilters.cs, Carving/Plugins/SevenZip/LzmaDecoder.cs, Carving/Plugins/SevenZip/Ppmd7.cs, Carving/Plugins/SevenZip/Ppmd8.cs, Carving/Plugins/SevenZip/SevenZipCarver.cs, Carving/Plugins/SevenZip/SevenZipExtractor.cs, Modules/FileSystems/SevenZipArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.