From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Library:Libpng" |
|---|
| claim | "libpng's writer rewrites the zlib CMF byte of the first IDAT to the smallest window (256 bytes to 16 KiB) that covers the whole inflated image when that is at most 16384 bytes, fixing FLG's check bits; and it emits IDAT chunks of PNG_ZBUF_SIZE = 8192 bytes except the last (png_set_compression_buffer_size changes it). Small libpng-written PNGs therefore start their zlib stream with 08/18/28/38/48/58/68 instead of 78." |
|---|
| scope | | level | "library" |
|---|
| applies_to | "Library:Libpng" |
|---|
| observed_in | |
|---|
|
|---|
| data | | function | "optimize_cmf" |
|---|
| effect | "CMF window shrunk; IDAT data split at 8192 bytes" |
|---|
| condition | "inflated image size <= 16384 bytes; PNG_WRITE_OPTIMIZE_CMF_SUPPORTED (default)" |
|---|
| test_vectors | | input | "libpng contrib/testpngs/gray-8.png (inflated image 257 bytes)" |
|---|
| expected | "IDAT starts 18 D3 (512-byte window)" |
|---|
|
|
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "optimize_cmf(data, data_size): if data_size <= 16384 ... while (z_cinfo > 0 && data_size <= half_z_window_size); png_write_complete_chunk(png_ptr, png_IDAT, data, size) when the zbuffer is full" |
|---|
| repo | "https://github.com/pnggroup/libpng" |
|---|
| commit | "cd952f49f95bb27154ae77dbb103032d95f6e580" |
|---|
| path | "pngwutil.c" |
|---|
| lines | "267-304, 990-1010" |
|---|
|
| type | "source" |
|---|
| detail | "#define PNG_ZBUF_SIZE 8192" |
|---|
| repo | "https://github.com/pnggroup/libpng" |
|---|
| commit | "cd952f49f95bb27154ae77dbb103032d95f6e580" |
|---|
| path | "scripts/pnglibconf.h.prebuilt" |
|---|
| lines | "225" |
|---|
|
| type | "runtime_test" |
|---|
| detail | "All 64 libpng-made images in contrib/testpngs with an inflated size <= 16384 use exactly the minimal window; the 40 larger ones use 0x78. PngSuite (other tools) also uses minimal windows, so this is a hint, not proof" |
|---|
|
|
|---|
| confidence | "medium" |
|---|
| related | |
|---|
| key | "Writer zlib window and IDAT size" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T08:50:45.503Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-18T21:44:23.482Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read libpng pngwutil.c at cd952f49 optimize_cmf (lines 267-304): applies when data_size <= 16384, halves the window while z_cinfo > 0 and data_size <= half window, rewrites CMF and recomputes FLG check bits; PNG_ZBUF_SIZE 8192 in pnglibconf.h.prebuilt." |
|---|
| notes | "The IDAT split lines (990-1010) and the contrib/testpngs runtime test were not re-checked." |
|---|
|
|
|---|