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

Library:Libbrotli

From ReverseEngineering.wiki
Library
Developer Google
Platforms portable C (also Java, C#, Go, JavaScript ports)
Versions 0.4.0 (2016) ... 1.0.9 (2020), 1.1.0 (2023-08), 1.2.0 (2025-10)
License MIT
Website https://github.com/google/brotli
On this wiki Facts · Code · Notes · Topics

Google's reference Brotli implementation (C, MIT): libbrotlicommon (static dictionary, transforms, context tables), libbrotlidec (BrotliDecoder*) and libbrotlienc (BrotliEncoder*), shipped as shared libraries or linked statically into browsers, runtimes (.NET, Node.js), web servers and font tools. Its tables, error strings and BrotliDecoderVersion identify it and its version in a binary.

Overview

The reference implementation of Format:Brotli (RFC 7932), developed by Google at https://github.com/google/brotli under the MIT license. The C code is split into three libraries that are built as shared libraries (libbrotlicommon, libbrotlidec, libbrotlienc; .so.1 on Linux, libbrotli*.dll with MinGW) or compiled straight into the host program:

  • common (c/common): the RFC 7932 static dictionary (kBrotliDictionary, 122,784 bytes of words), the transform table, the context lookup table, the prefix-code range table and, since 1.1.0, shared/compound dictionaries.
  • dec (c/dec): the decoder (BrotliDecoder*), a resumable state machine that stops whenever input or output runs out.
  • enc (c/enc): the encoder (BrotliEncoder*), qualities 0-11, window 10-24 bits (up to 30 with the large-window extension).

The same repository has ports that do not share the C tables' layout: a Java decoder (java/org/brotli/dec, package org.brotli.dec), C#, JavaScript, a pure-Go decoder (go/brotli) next to the cbrotli wrapper of the C library, and the Python extension _brotli that wraps the C code. The Java port stores the dictionary in DictionaryData.java as string constants (DATA0, DATA1) with most characters XORed with 3, so a JAR or DEX holding it contains wjnfgltmojefofewab`h`lgfgbwbpkltlmozpjwf instead of the plain words.

Identification

What Where Versions
Dictionary data, 122,784 bytes starting timedownlifeleftbackcodedatashowonlysitecityopenjustlikefree..., SHA-256 20e42eb1...35c70 common (kBrotliDictionaryData) all; see Format:Brotli#Identification
kBrotliDictionary header: size_bits_by_length 00 00 00 00 0A 0A 0B 0B 0A 0A 0A 0A 0A 09 09 08 07 07 08 07 07 06 06 05 05 00 00 00 00 00 00 00 followed by 32 uint32 offsets (0 x5, 4096, 9216, 21504, ... 122016, then 122784 x7) common 0.5.2+; after it come A0 DF 01 00 (data_size 122784, a size_t) and the data pointer since 1.0.0, the data itself in 0.5.x-0.6.x
kPrefixSuffix, the transform affixes as length-prefixed strings: 01 20 02 2C 20 08 20 6F 66 20 74 68 65 20 04 20 6F 66 20 (\1 \2, \10 of the \4 of ...) common (dec before 1.0.3) 1.0.3+; 0.4.0-1.0.2 use a 208-byte NUL-separated form 00 20 00 2C 20 00 20 6F 66 20 74 68 65 20 00
_kBrotliContextLookupTable, 2048 bytes (4 context modes x 2 x 256); its UTF8 part starts 00 00 00 00 00 00 00 00 00 04 04 00 00 04 00 00 + 16 zeros + 08 0C 10 0C 0C 14 0C 10 18 1C 0C 0C 20 0C 24 0C common, exported by the DLL 1.0.8+ under this name
Decoder error strings _ERROR_FORMAT_EXUBERANT_NIBBLE, _ERROR_FORMAT_PADDING_1, _ERROR_DICTIONARY_NOT_SET, _ERROR_ALLOC_RING_BUFFER_1, _ERROR_UNREACHABLE ... (BrotliDecoderErrorString returns #PREFIX #NAME of each code) dec 0.5.2+; gone when the linker drops an unused BrotliDecoderErrorString (.NET 8/9 builds)
Exports BrotliDecoderCreateInstance, BrotliDecoderDecompressStream, BrotliDecoderDecompress, BrotliDecoderVersion, BrotliDecoderErrorString, BrotliEncoderCreateInstance, BrotliEncoderCompress, BrotliEncoderCompressStream, BrotliEncoderSetParameter, BrotliEncoderVersion, BrotliGetDictionary, BrotliGetTransforms, BrotliTransformDictionaryWord, _kBrotliContextLookupTable, _kBrotliPrefixCodeRanges ... DLLs, and DLLs that re-export them (.NET's System.IO.Compression.Native) 0.6.0+ API; BrotliDecoderAttachDictionary, BrotliSharedDictionary*, BrotliDecoderSetMetadataCallbacks since 1.1.0

Version

BrotliDecoderVersion() and BrotliEncoderVersion() return (major << 24) | (minor << 12) | patch (c/common/version.h): 0x1000009 for 1.0.9, 0x1001000 for 1.1.0, 0x1002000 for 1.2.0. On x86 they compile to mov eax, imm32; ret, e.g. B8 00 10 00 01 C3 for 1.1.0; with MSVC identical-code folding both exports point to the same function. Releases: 0.4.0 (2016-06), 0.5.2, 0.6.0, 1.0.0 (2017-09), 1.0.9 (2020-08), 1.1.0 (2023-08), 1.2.0 (2025-10).

API

  • One-shot: BrotliDecoderDecompress(encoded_size, encoded, &decoded_size, decoded) returns a BrotliDecoderResult; BrotliEncoderCompress(quality, lgwin, mode, input_size, input, &encoded_size, encoded) returns BROTLI_TRUE/FALSE. Empty input encodes to the single byte 06; when the result would exceed BrotliEncoderMaxCompressedSize(n) (n + 6 + 4 x (n >> 14)) it writes a stored stream starting 21 03 instead.
  • Streaming: BrotliDecoderCreateInstance(alloc, free, opaque), BrotliDecoderDecompressStream(state, &available_in, &next_in, &available_out, &next_out, &total_out) (results ERROR 0, SUCCESS 1, NEEDS_MORE_INPUT 2, NEEDS_MORE_OUTPUT 3), BrotliDecoderGetErrorCode, BrotliDecoderDestroyInstance; the encoder side uses BrotliEncoderSetParameter (MODE 0, QUALITY 1, LGWIN 2, LGBLOCK 3, LARGE_WINDOW 6, ...) and BrotliEncoderCompressStream with BROTLI_OPERATION_PROCESS / FLUSH / FINISH / EMIT_METADATA.
  • Defaults: quality 11 (BROTLI_DEFAULT_QUALITY), window 22 (BROTLI_DEFAULT_WINDOW), mode GENERIC (0; TEXT 1, FONT 2). The brotli CLI instead starts from window 24 and lowers it to the smallest window that holds the input file.

Where it appears

Checked (read-only scan of the files with the scanner under #Code & repositories):

Binary What was found
libbrotlicommon.dll, libbrotlidec.dll, libbrotlienc.dll of Git for Windows 2.47.1 (MinGW-w64, x64) version 1.1.0; the tables in libbrotlicommon, error strings in libbrotlidec
System.IO.Compression.Native.dll of .NET 8.0.31, 9.0.19, 10.0.11 (x64) dictionary, kBrotliDictionary header, kPrefixSuffix and context table in all three; .NET 10 exports the whole API (38 functions, version 1.1.0), .NET 8 and 9 only the 11 functions BrotliStream needs and contain no error strings
node.exe 24.13.0 for Windows (x64) all tables and the error strings, statically linked, no exports

Unverified: Chromium and Electron (network stack and WOFF2 fonts), Firefox, curl/libcurl builds with brotli support, nginx's ngx_brotli, Android's libbrotli, game engines that load WOFF2 or .br web builds. Check with the scanner or the dictionary string.

Code & repositories

  • Brotli decoder and library scanner (Python) — Dependency-free Brotli (RFC 7932) decoder written from the RFC and the google/brotli tables, with a header dump (window bits, meta-blocks, block types, context modes), a writer for valid stored stream
  • https://github.com/google/brotli @ 86ee1f65f62d6272345dee751d49e7d1f01c2b11 · license: MIT
    Reference implementation (MIT): the C library (c/common, c/dec, c/enc; libbrotlicommon/dec/enc), the brotli CLI (c/tools/brotli.c), Java, C#, Go, JavaScript and Python bindings or ports, the static dictionary as c/common/dictionary.bin, release tags v0.1.0 to v1.2.0, a reference corpus (tests/testdata: 45 .compressed files next to their originals) and 46 synthetic valid/invalid streams in java/org/brotli/dec/SynthTest.java; research/brotlidump.py is an official Python stream dumper.
    Tested on: Read at this commit (1.2.0 + later commits) and at tags v0.4.0, v0.5.2, v0.6.0, v1.0.0-v1.0.9, v1.1.0, v1.2.0; all tests/testdata streams and SynthTest streams decoded with the Python decoder on this wiki; tables compared with Git for Windows (1.1.0), .NET 8/9/10 and node.exe 24.13 binaries. Not built. · checked 2026-10-17; last activity 2026-10-15; Note: the latest release ships binaries; the wiki links only the source, never the binaries

Pitfalls

  • The common library holds the tables; a decoder-only DLL (libbrotlidec) contains none of them. The Git for Windows 1.1.0 build imports _kBrotliContextLookupTable, _kBrotliPrefixCodeRanges, BrotliTransformDictionaryWord, the BrotliSharedDictionary* functions and the default allocators from libbrotlicommon.dll.
  • Builds with BROTLI_EXTERNAL_DICTIONARY_DATA leave the dictionary out (kBrotliDictionary.data is NULL until BrotliSetDictionaryData is called), so the dictionary-string search finds nothing while the 160-byte header is still there.
  • Other implementations do not share the C struct layout: the Java port keeps the dictionary XOR-3 encoded (above); unverified, third-party decoders such as Rust's brotli-decompressor and Go's andybalholm/brotli embed the plain dictionary bytes. Search for the dictionary string, not the header.

Evidence & references

  • https://github.com/google/brotli at commit 86ee1f65f62d6272345dee751d49e7d1f01c2b11, files c/common/dictionary.h (lines 18-41), c/common/dictionary.c (lines 17-48), c/common/transform.c (lines 14-37), c/common/context.c, c/common/version.h, c/include/brotli/decode.h (lines 35-117), c/include/brotli/encode.h (lines 53-92, 168-216), c/dec/decode.c (lines 2411-2434, 2980-2994), c/enc/encode.c (lines 1263-1363, 1764-1766), java/org/brotli/dec/DictionaryData.java; history checked at tags v0.4.0 to v1.2.0.
  • Binaries: read-only byte scans and PE export/import parsing of the files listed under Where it appears; nothing was executed or loaded.