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:Zlib-ng

From ReverseEngineering.wiki
Library
Developer zlib-ng contributors
Versions 2.x (2.3.90 in the current repository head)
License Zlib
Website https://github.com/zlib-ng/zlib-ng
On this wiki Facts · Code · Notes · Topics

The zlib fork by Nathan Moinvaziri and others (Zlib license) with SIMD-optimised deflate/inflate, CRC-32 and Adler-32, built either as a native-API library (zng_* functions, zlib-ng.h) or in zlib-compat mode that exports the original zlib names with a ZLIB_VERSION ending in .zlib-ng; used as a replacement system zlib by some distributions and wrapped by Rust crates.

Overview

zlib-ng rewrote deflate and many hot paths of Library:Zlib (new deflate strategies, SIMD checksums, different deflate_state), but its inflate keeps zlib's table-building code (inftrees.c) and stream format. Built in compat mode it is a drop-in libz.so.1; native mode exports zng_deflateInit, zng_inflate, zng_compress, zng_uncompress, zng_crc32, zng_adler32 and zlibng_version.

Identification

  • Version strings (zlib-ng.h.in, zlib.h.in): ZLIBNG_VERSION is "2.3.90" at the pinned commit; in compat mode ZLIB_VERSION is "1.3.2.zlib-ng" (the zlib version it tracks plus the suffix), returned by zlibVersion(), and zlibng_version() returns the zlib-ng number. Callers pass the zlib-style string to inflateInit_/deflateInit_, so a "1.3.x.zlib-ng" literal at an init call identifies it.
  • Inflate tables are zlib's: src/inftrees.c lines 168-181 hold lbase, lext, dbase, dext with the same values as madler/zlib 1.3.2 (lext ends 199, 75; dext ends 64, 64). So the lext/dext version pairs of Library:Zlib#Versions cannot tell zlib from zlib-ng; use the version string, the exports, or the zng_ names.
  • CRC and checksum code: runtime CPU dispatch (functable) with PCLMULQDQ/VPCLMULQDQ, AVX2, NEON and others; the generic fallback keeps the ordinary reflected CRC-32 table: crc32_braid_tbl.h (commit 1727258b764262c73149014cdf6a39bd551b3bd5, line 10) declares static const uint32_t crc_table[] starting 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, the same first entries as zlib's, followed by further braid tables (BRAID_N is 5, crc32_braid_p.h line 7; BRAID_W is 8 or 4). So a 256-entry CRC table starting 0x77073096 in a zlib-ng build is not evidence against zlib-ng, and not evidence for it either.

Code & repositories

  • https://github.com/zlib-ng/zlib-ng @ 1727258b764262c73149014cdf6a39bd551b3bd5 · license: Zlib
    zlib-ng source: zlib-ng.h.in and zlib.h.in carry the version macros, inftrees.c the unchanged inflate tables; arch/ has the SIMD code.
    Tested on: source read, not run: source read at the pinned commit; nothing built or run · checked 2026-10-18; last activity 2026-10-17; Note: the latest release ships binaries; the wiki links only the source, never the binaries

Pitfalls

  • A distribution with zlib-ng in compat mode shows libz.so.1 and zlib-compatible exports; check zlibVersion() output for the .zlib-ng suffix.
  • The lext tail pairs differ between zlib-ng releases, so do not use one pair for all zlib-ng: inftrees.c has ... 16, 77, 202 at tag 2.0.0 (line 59), ... 16, 203, 77 at tag 2.2.1 (line 57) and ... 16, 199, 75 at the pinned head commit (line 173). Compare them with the zlib pairs on Library:Zlib#Versions. Releases before 2.0.0 were not read.

Evidence & references

  • zlib-ng/zlib-ng commit 1727258b764262c73149014cdf6a39bd551b3bd5: zlib-ng.h.in (lines 51-53, 221), zlib.h.in (lines 52-61), inftrees.c (168-181). Read only.