Format:LZNT1
| On this wiki | Facts · Code · Notes · Topics |
|---|
Windows NT's LZ77 compression (COMPRESSION_FORMAT_LZNT1 = 2), used by NTFS file compression and RtlCompressBuffer: 4096-byte chunks each with a 16-bit header, flag bytes of 8 items and a variable offset/length split.
Overview
LZNT1 is the oldest Windows compression format, covered by [MS-XCA] (see Format:Xpress) and implemented by RtlCompressBuffer / RtlDecompressBuffer / RtlDecompressBufferEx in ntdll with format COMPRESSION_FORMAT_LZNT1 (2, optionally ORed with COMPRESSION_ENGINE_MAXIMUM 0x100). NTFS file compression uses the same chunk layout: ntfs-3g libntfs-3g/compress.c (7f0f841) defines sub-blocks of NTFS_SB_SIZE 0x1000 bytes with a 16-bit header holding a 0x0fff size mask and the NTFS_SB_IS_COMPRESSED flag 0x8000, with symbol and phrase tokens in flag-byte groups (the name LZNT1 itself does not appear in that file).
Layout (from Wine's ntdll)
- Data is a sequence of chunks, each covering up to 0x1000 uncompressed bytes. A chunk starts with a 16-bit little-endian header: bits 0-11 = chunk data size minus 1, bit 15 = chunk is compressed (clear means stored bytes). A header of 0 ends the stream.
- In a compressed chunk a flag byte comes first, then 8 items (low bit first): bit 0 = one literal byte, bit 1 = a 16-bit match token.
- Match token: the number of displacement bits grows with the position inside the chunk, from 4 up to 12; length_bits = 16 - displacement_bits; length = (token & mask) + 3; displacement = (token >> length_bits) + 1. See Fact:LZNT1/behavior/Chunk and match coding.
- Wine reports a decompression workspace of 0x1000 bytes for this format.
Identification
A stream is a sequence of chunks with no file magic. Each chunk starts with a little-endian 16-bit header: low 12 bits = chunk data size minus 1, bit 15 = compressed flag; the MS-XCA description puts the signature value 3 in bits 12-14, so a compressed chunk header reads xx Bx (top nibble 0xB) and an uncompressed one xx 3x. A zero header word ends the stream.
Checked: Wine dlls/ntdll/rtl.c @ 7298a818b7, lznt1_decompress (lines 1208-1270 read) takes the size as (header & 0xfff) + 1, tests header & 0x8000 for compressed and treats a zero header as the end. Wine does not test the signature bits, so the top-nibble 0xB/0x3 rule comes from the Microsoft specification and is Unverified in code here.
Code & repositories
- https://github.com/wine-mirror/wine @
7298a818b79446bae153b8d5aa27235ab3703bf9· license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize COPYING.LIB)
Wine's ntdll implements LZNT1 RtlDecompressBuffer in dlls/ntdll/rtl.c (LGPL-2.1+).
Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-10-16
See also
Format:Xpress, Format:LZX, Technique:Identifying compression libraries in binaries