Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Bzip2

From ReverseEngineering.wiki
Format
Magic 42 5A 68 ('BZh') + '1'..'9'
Extensions .bz2, .tbz2
Endianness bit stream, most significant bit first; CRC big-endian
On this wiki Facts · Code · Notes · Topics

Julian Seward's block-sorting compression format (.bz2): a stream header 'BZh' plus a block-size digit, blocks introduced by the 48-bit magic 0x314159265359 (pi), and an end-of-stream magic 0x177245385090 (sqrt(pi)) followed by a combined CRC.

Overview

A bzip2 file is a bit stream (most significant bit first, not byte aligned after the 4-byte header). Each block holds up to 100k to 900k bytes of Burrows-Wheeler-transformed, move-to-front and Huffman coded data. Concatenated streams are legal, so a file can contain several 'BZh' headers.

Identification

  • Stream header: 42 5A 68 ('BZh') then the ASCII digit '1' to '9' (0x31-0x39): the block size in units of 100,000 bytes (so BZh9 = 900k, the default). The decoder rejects anything outside '1'..'9'.
  • Each block starts with the 48-bit magic 31 41 59 26 53 59 (BCD digits of pi), followed by the 32-bit block CRC, a 'randomised' bit (always 0 since 0.9.5) and a 24-bit origPtr.
  • The stream ends with 17 72 45 38 50 90 (digits of sqrt(pi)) and a 32-bit combined CRC. Because the stream is a bit stream, these 48-bit magics appear at arbitrary bit offsets after the first block, so a byte-aligned search finds only the first block (offset 4).
  • The CRC is the big-endian (MSB-first) CRC-32 with polynomial 0x04C11DB7, not the reflected zlib one. Its table starts 00000000 04C11DB7 09823B6E 0D4326D9 (Library:Bzip2).

Related

Technique:Identifying compression libraries in binaries, Library:Bzip2.

Code & repositories

  • https://github.com/libarchive/bzip2 @ 1ea1ac188ad4b9cb662e3f8314673c63df95a589 · license: bzip2-1.0.6 (declared by the contributor; GitHub's detector did not recognize COPYING)
    GitHub mirror of the reference bzip2 source (1.0.8)
    Tested on: source read, not run: source only · checked 2026-10-18; last activity 2022-04-08