XZ (.xz)

LZMA2-based container with integrity checks.

Overview

An xz file has a stream header (magic FD 37 7A 58 5A 00, flags, CRC-32), one or more blocks each with a block header, a filter chain (LZMA2 with optional BCJ and Delta filters), padding and a check (CRC-32, CRC-64, SHA-256), followed by an index and a stream footer (magic YZ).

Where it is used

  • Linux package archives and kernel source tarballs.
  • Compressed backups.

History

  • Developed by Lasse Collin from 2009 as the successor to the LZMA-alone format.

Status today

  • Widely used; actively maintained in XZ Utils.

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.

XzArchiveModule.ParseStream buffer header · XzArchiveModule.cs

OffsetSizeTypeFieldNotes
0x06bytes–
0x71u8Check Size

Walk.ReadBlock buffer header · XzCarver.cs

OffsetSizeTypeFieldNotes
0x01u8–
0x11u8Flags
headerSize – 44u32 LE–

Walk.ReadStream buffer footer · XzCarver.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x44u32 LE–
0x46bytes–
0x81u8–
0x91u8–
0xA1u8–
0xB1u8–

Walk.ReadStream buffer header · XzCarver.cs

OffsetSizeTypeFieldNotes
0x06bytes–
0x62bytes–
0x61u8–
0x71u8Check Type
0x71u8–
0x84u32 LE–

Walk.StreamHeaderValid buffer header · XzCarver.cs

OffsetSizeTypeFieldNotes
0x06bytes–
0x62bytes–
0x61u8–
0x71u8–
0x84u32 LE–

Walk.VerifyCheck buffer check · XzCarver.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x08u64 LE–

XzDecoder.Apply buffer properties · XzDecoder.cs

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x01u8Distance

XzDecoder.X86 buffer b · XzDecoder.cs

OffsetSizeTypeFieldNotes
i + 14u32 LESrc
i + 41u8–

Other fields read

Read inOffsetSizeTypeFieldNotes
Walk.ReadStream0x04u32 LE–
XzDecoder.PowerPci4u32 BEInstruction
XzDecoder.Sparci4u32 BEInstruction

Constants

General XzCarver

NameValueTypeNotes
Magic[0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00]byte[]

General XzDecoder

NameValueTypeNotes
MaskToAllowed[true, true, true, false, true, false, false, false]bool[]
MaskToBit[0, 1, 2, 2, 3, 3, 3, 3]int[]

General XzArchiveModule

NameValueTypeNotes
Magic[0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00]byte[]

Implementation limits reader

ClassNameValueNotes
XzCarverMaxVerifyBlock64 * 1024 * 1024
XzCarverSniffBytes8 * 1024 * 1024
Structures and constants were extracted from: Carving/Plugins/Compressed/XzCarver.cs, IO/Compression/XzDecoder.cs, Modules/FileSystems/XzArchiveModule.cs. Prose sections are a summary from public sources; verify details before relying on them.