Library:Libpng
| Developer | PNG Reference Library Authors (Guy Eric Schalnat, Andreas Dilger, Glenn Randers-Pehrson, Cosmin Truta and others) |
|---|---|
| Uses | Library:Zlib |
| Platforms | any (portable C; libpng16.dll, libpng16-16.dll (MinGW), libpng16.so.16, libpng16.16.dylib) |
| Versions | 0.1 (March 1995) to 1.6.59 (September 2026); 1.8.0 in development on the libpng18 branch |
| License | libpng-2.0 (PNG Reference Library License version 2) |
| Website | http://www.libpng.org/pub/png/libpng.html |
| On this wiki | Facts · Code · Notes · Topics |
The official PNG reference library (C, on top of zlib), linked as libpng16.dll / libpng16.so.16 or statically into image libraries, engines and applications; the 1.6 series (2013-2026) is by far the most common. Its simplified-API sRGB tables, the NUL-terminated version string passed by every caller and the chunk names used as 32-bit immediates identify it even in stripped static builds.
Overview
libpng is the official reference library for reading and writing Format:PNG, in C, on top of Library:Zlib (it calls inflate/deflate and zlib's crc32 for chunk CRCs). The 1.6 series (1.6.0, 2013, to 1.6.59, 2026) is what you meet in almost every binary: as a DLL (libpng16.dll, libpng16-16.dll from MinGW builds, libpng16.so.16, libpng16.16.dylib) or statically linked into image libraries and programs (GD, SDL_image, wxWidgets, Qt, Library:FreeType's PNG color glyphs (optional, FT_CONFIG_OPTION_USE_PNG), game engines, emulators). The 1.2 series (to 1.2.59, 2017) survives in old software. Development continues on the libpng18 branch (1.8.0, which adds APNG decoding); 1.7 never had a stable release.
Identification
What survives in a build, from most to least useful:
- Simplified-API tables (png.c, 1.6.0 and later):
png_sRGB_table[256](u16, starts0, 20, 40, 60, 80, 99, 119, 139),png_sRGB_base[512](u16, starts128, 1782, 3383, 4644) andpng_sRGB_delta[512](bytes, starts207, 201, 158, 129, 113, 100). They are byte-identical from 1.6.0 to the 1.8 branch, so they prove libpng 1.6+ but not the exact version. They were present in all three builds checked (MSVC static, MSVC DLL, MinGW static). - Version strings: every application call
png_create_read_struct(PNG_LIBPNG_VER_STRING, ...)passes the header version ("1.6.34"), and the library compares it with its own copy, so the NUL-terminated string is in every build even when the copyright text is gone. Next to it: the warning textApplication built with libpng-and " but running with " (with the spaces). - Copyright banner returned by
png_get_copyright():"\nlibpng version 1.6.59\nCopyright (c) 2018-2026 Cosmin Truta\n..."; releases up to 1.6.35 (and all of 1.0-1.5) add the release date:"libpng version 1.6.34 - September 29, 2017". It is a string literal inside the function, so it is present when the function is linked (every DLL, which exports it) and gone when a static user never calls it: PHP 8.3's MSVC-builtphp_gd.dllcarries libpng 1.6.34 without it. - Chunk names as 32-bit immediates (1.5.6 and later): chunk types are compared as
png_uint_32built withPNG_U32('I','H','D','R')=0x49484452, so little-endian code holds the reversed bytes:81 F9 52 44 48 49(cmp ecx, 'IHDR'),3D 52 44 48 49(cmp eax, ...) andBA 52 44 48 49(mov edx, ..., the chunk name argument ofpng_write_complete_chunk). Up to 1.5.5 the names were 5-byte arrayspng_IHDR[5] = "IHDR\0"compared withmemcmp. - Adam7 tables
png_pass_start {0,4,0,2,0,1,0},png_pass_inc {8,8,4,4,2,2,1},png_pass_ystart {0,0,4,0,2,0,1},png_pass_yinc {8,8,8,4,4,2,2}(pngrutil.c, and pngwutil.c for the writer). Short, so use them only next to other evidence; GCC placed the four arrays back to back in reverse order. - Strings:
Not a PNG file,PNG file corrupted by ASCII conversion,Missing IHDR before IDAT,Too many IDATs found,Invalid IHDR data,Call to NULL read function,libpng does not support gamma+background+rgb_to_gray,invalid window size (libpng),Ignoring invalid time value; all 13 searched for were in all three builds checked. - Exports (DLL builds):
png_create_read_struct,png_create_write_struct,png_set_longjmp_fn,png_read_info,png_get_IHDR,png_image_begin_read_from_memory,png_get_libpng_ver,png_access_version_number(returnsPNG_LIBPNG_VER, e.g. 10659 for 1.6.59).
The wiki's pngscan script searches a file for all of these and prints the version; export_symbols with subject Library:Libpng gives a Ghidra/IDA script that finds the signature facts in your binary.
Versions
Version markers you can see from outside, read from the release tags of the official repository:
| Marker | First release |
|---|---|
png_set_longjmp_fn (the png_jmpbuf() macro calls it) |
1.5.0 |
chunk names as integers (PNG_CHUNK, later PNG_U32) |
1.5.6 |
simplified API (png_image_*) and the sRGB tables |
1.6.0 |
eXIf support |
1.6.31 |
| release date dropped from the copyright banner | 1.6.36 |
cICP support |
1.6.45 |
mDCV, cLLI support |
1.6.46 |
table-driven chunk dispatch (read_chunks[]), names acTL/fcTL/fdAT known |
1.6.47 |
In 1.6.47 and later the APNG chunk handlers are defined as NULL: libpng 1.6 knows the names but treats the chunks as unknown and decodes only the default image. APNG decoding is on the libpng18 branch. Some distributions and Mozilla's bundled copy apply an out-of-tree APNG patch to 1.6 instead; unverified: a 1.6 build that exports png_get_acTL carries that patch (test: list the exports of a distribution's patched libpng16).
API overview
png_create_read_struct(user_png_ver, error_ptr, error_fn, warn_fn)thenpng_create_info_struct,png_init_ioorpng_set_read_fn,png_read_info,png_get_IHDR, thepng_set_*transforms,png_read_image/png_read_row,png_read_end,png_destroy_read_struct. The write side mirrors it.png_user_version_check()compares the caller's version string with the library's only up to the second dot ("1.6."); on a mismatch it warnsApplication built with libpng-<app> but running with <lib>andpng_create_*_structreturns NULL. A 1.6.x program therefore runs with any 1.6.y DLL.- Errors use
setjmp/longjmp:setjmp(png_jmpbuf(png_ptr))expands tosetjmp(*png_set_longjmp_fn(png_ptr, longjmp, sizeof(jmp_buf))), so each caller's error path starts with a call that passes the C library'slongjmpand a constantsizeof(jmp_buf). Unverified values of that constant: 256 (MSVC x64), 64 (MSVC x86), 200 (glibc x86-64). - Simplified API (1.6.0+): fill a
png_imagewithversion = PNG_IMAGE_VERSION(1), callpng_image_begin_read_from_file/_stdio/_memory, setformat, thenpng_image_finish_read(&image, background, buffer, row_stride, colormap); errors come back inimage.message.
Core data structures
png_structandpng_infoare opaque and their layout depends on the build options inpnglibconf.h; do not expect stable offsets between builds.png_image(public, png.h) is stable:opaquepointer, then u32version,width,height,format,flags,colormap_entries,warning_or_error, thenchar message[64](96 bytes on 32-bit, 104 on 64-bit). Theformatbits (PNG_FORMAT_FLAG_ALPHA 1,COLOR 2,LINEAR 4,COLORMAP 8,BGR 0x10,AFIRST 0x20,ASSOCIATED_ALPHA 0x40) makePNG_FORMAT_RGBA3,PNG_FORMAT_BGRA0x13,PNG_FORMAT_ARGB0x23 recognisable as immediates.
Code & repositories
- https://github.com/pnggroup/libpng @
cd952f49f95bb27154ae77dbb103032d95f6e580· license: libpng-2.0 (declared: the detector found none; check the repository)
The official libpng source (tag v1.6.59; branches libpng16 for the 1.6 series, libpng18 for 1.8 with APNG, libpng12 and older). contrib/pngsuite holds Willem van Schaik's PngSuite conformance images (basic and interlaced) and contrib/testpngs images written by libpng's own makepng, including malformed 'crashers': good free test data for any PNG parser. License: PNG Reference Library License version 2 (LICENSE.md).
Tested on: Read at tag v1.6.59 and at every v1.5.x/v1.6.x tag for the version markers; pngdump run over contrib/pngsuite and contrib/testpngs (166 images); not built (no C compiler on the test machine). · checked 2026-10-17; last activity 2026-10-12
Pitfalls
- The copyright banner is missing from statically linked builds that never call
png_get_copyright(); search for the version string and the sRGB tables instead. - A NUL-terminated
"1.2.x"or"1.3.x"string is just as likely zlib's version; libpng 1.6+ builds also contain zlib's string (1.3.1next to1.6.50in VLC's PNG plugin). - The
libpng16-16.dllshipped with the Steam client (1.6.58, MSVC linker 14.44, x64) was linked incrementally: all 256 exports point to 5-byteE9 rel32jump thunks at the start of.text(for examplepng_set_longjmp_fn0x10AF jumps to 0xDB80), so follow the jump before comparing function bytes or sizes with another build. - Default limits (scripts/pnglibconf.h.prebuilt, used by most builds):
PNG_USER_WIDTH_MAXandPNG_USER_HEIGHT_MAX1,000,000 pixels,PNG_USER_CHUNK_MALLOC_MAX8,000,000 bytes for one chunk allocation,PNG_USER_CHUNK_CACHE_MAX1000 unknown/text chunks. Valid huge PNGs fail in libpng programs with the warning "Image width exceeds user limit in IHDR" followed by the error "Invalid IHDR data" unless the program callspng_set_user_limits. - Files written by libpng: the first
IDATis rewritten to the smallest zlib window that covers the inflated image when that is at most 16 KiB (optimize_cmf, pngwutil.c, since 1.2.x), so small libpng PNGs start their zlib stream with08,18, ...68instead of78; andIDATchunks are 8192 bytes (PNG_ZBUF_SIZE) except the last unless the program callspng_set_compression_buffer_size. Both are hints, not proof, that libpng wrote a file (PngSuite, made with other tools, also uses minimal windows).
Evidence & references
- Source read at https://github.com/pnggroup/libpng tag v1.6.59 (commit cd952f49f95bb27154ae77dbb103032d95f6e580); feature first-appearance found with
git show <tag>:<file>over all v1.5.x and v1.6.x tags; older formats checked at v1.2.59, v1.4.22, v1.5.30. - Scanned three Windows x64 builds with pngscan: VLC's
libpng_plugin.dll(libpng 1.6.50, MinGW GCC, static), Steam'slibpng16-16.dll(1.6.58, MSVC linker 14.44, DLL), PHP 8.3.30'sphp_gd.dll(1.6.34, MSVC linker 14.29, static, no banner); no false positives on python312.dll and git.exe.