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:Stb

From ReverseEngineering.wiki
Library
Developer Sean Barrett and contributors (nothings/stb)
Platforms any C/C++ (header-only, compiled into the application)
Versions stb_image 2.30, stb_image_write 1.16, stb_truetype 1.26, stb_vorbis 1.22, stb_image_resize2 2.18, stb_rect_pack 1.01, stb_sprintf 1.10 (header comments at the commit below)
License MIT or public domain (choice, stated at the end of each header)
Website https://github.com/nothings/stb
On this wiki Facts · Code · Notes · Topics

Sean Barrett's single-header public-domain C libraries (stb_image, stb_image_write, stb_truetype, stb_vorbis, stb_image_resize2, stb_rect_pack, stb_sprintf...) compiled into the host program. They export nothing, so a static copy is recognized by its short error strings (stbi_failure_reason texts such as "bad png sig", "unknown image type"), not by a version string.

Overview

Each stb library is one .h file; one translation unit defines STB_IMAGE_IMPLEMENTATION (etc.) before including it, so the code lands inside the application with no DLL and no exports. stb_image reads JPEG (baseline and progressive), PNG (8/16-bit), TGA, BMP, PSD, GIF, HDR (Radiance) and PIC and PNM; it is used for textures in countless games and tools. The header comments carry a version (stb_image - v2.30), but it is not compiled into the binary (only #define STBI_VERSION 1 in the header, which is not stored either).

Identification of stb_image

  1. Failure reason strings. stbi__err(x,y) stores the short text x in stbi__g_failure_reason, which stbi_failure_reason() returns; the long second text (e.g. Corrupt JPEG, Corrupt PNG) is only used when STBI_FAILURE_USERMSG is defined, and STBI_NO_FAILURE_STRINGS removes all of them. The short strings of the loaders at the commit below (a build keeps those of the formats it did not disable with STBI_NO_JPEG, STBI_NO_PNG, STBI_NO_BMP, STBI_NO_PSD, STBI_NO_TGA, STBI_NO_GIF, STBI_NO_HDR, STBI_NO_PIC, STBI_NO_PNM):
  • common: outofmem, unknown image type, can't fopen, 0-pixel image, too large, bad ctype, 1/2/4/8/16-bit only, unexpected end
  • PNG and its inflate: bad png sig, first not IHDR, multiple IHDR, bad IHDR len, no IDAT, no PLTE, invalid PLTE, tRNS after IDAT, tRNS before PLTE, bad tRNS len, invalid filter, bad filter method, bad interlace method, bad comp method, bad zlib header, no preset dict, bad compression, zlib corrupt, bad dist, bad codelengths, bad huffman code, read past buffer, outofdata, not enough pixels, IDAT size limit
  • JPEG: no SOI, no SOF, bad SOS, expected marker, unknown marker, bad DHT header, bad DQT table, bad DQT type, bad H, bad V, bad TQ, bad size list, bad code lengths, bad AC huff, bad DC huff, bad DNL height, bad delta, can't merge dc and ac, bad component count, bad SOF len, bad APP len, bad COM len, bad DRI len
  • others: not GIF, max value > 65535, integer parse overflow (PNM), invalid width, 0 width, no header height.
  1. Magic compares: PSD is tested as a big-endian u32 0x38425053 ('8BPS'); HDR as the header lines #?RADIANCE and #?RGBE.
  2. Exports are absent in a static build; the symbols appear only in unstripped builds or debug symbols: stbi_load, stbi_load_from_memory, stbi_failure_reason, stbi_image_free, stbi_set_flip_vertically_on_load, stbi__png_load, stbi__jpeg_decode_block.
  3. Other libraries: stb_vorbis defines an error enum (VORBIS__no_error, VORBIS_invalid_api_mixing, ...) and the API stb_vorbis_get_info; stb_truetype and stb_image_write have no user-visible strings. stb_image_write embeds a tiny zlib encoder (stbiw__zlib_*, fixed-Huffman blocks, stbiw__zlib_add(1,2) at line 916 of commit 2c980bb59875b0d32144a71867fbdebb2f77cd20). It is not text-free: its Radiance HDR writer outputs the header #?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n (line 770), which identifies it in written .hdr files. Its PNG, BMP, TGA and JPG writers were not searched for such text beyond this.

Pitfalls

  • Missing strings do not prove stb is absent: STBI_NO_FAILURE_STRINGS or a stripped, merged string table removes them. Unverified: then look at the shape of the code instead (own inflate, Huffman tables) or at the callers of the loader.
  • Unverified: forks and copies in other projects repeat the same short messages; confirm with a second string.
  • Because stb is compiled with the application, optimization and SIMD paths (the header mentions SSE2 and ARM fall-backs near line 268) vary per build; function bodies are not stable signatures.

Code & repositories

Source: https://github.com/nothings/stb (stb_image.h, stb_image_write.h, stb_truetype.h, stb_vorbis.c, ...).

  • https://github.com/nothings/stb @ 2c980bb59875b0d32144a71867fbdebb2f77cd20 · license: MIT OR Unlicense (declared by the contributor for the files used; GitHub reports Unlicense (read from LICENSE; GitHub's detector did not classify it) for the repository)
    stb single-header libraries; stb_image.h failure strings and stbi__err macro
    Tested on: source read, not run: read the source · checked 2026-10-18; last activity 2026-08-02

Evidence & references

Read in the repository at commit 2c980bb59875b0d32144a71867fbdebb2f77cd20: stb_image.h (stbi__err definitions near lines 1090-1100, stbi_failure_reason, error strings via grep of stbi__err calls), header comments of the other files.