#1865·stb

Two potential problems (or possibly hallucinations) from Gemini

Author: thealgebraistCreated Dec 13, 2025Updated Aug 22, 2026

test.c

  1. TGA Loader: Uninitialized Memory Leak (Security Risk) In the stbi__tga_load function, when loading standard (non-indexed, non-RLE) images, the code ignores the return value of stbi__getn.

The Bug: If the file ends prematurely (is truncated), stbi__getn returns 0 (failure), but the code continues without erroring. Since the image buffer (tga_data) was allocated with malloc (via stbi__malloc), it is not zero-initialized. The function will return a buffer containing random heap memory (garbage) where the file data is missing, which is a potential information leak.

Location: Line 1562.


  1. HDR Loader: Data Corruption via Improper Loop Reset In the stbi__hdr_load function, the code attempts to handle a specific error case where a scanline looks like Run-Length Encoding (RLE) but isn't. If this check fails, the code resets the pixel i and row j indices and jumps back to a label main_decode_loop.

The Bug: The reset j = 0 is incorrect if the parser is already processing a row deeper in the image (e.g., row 5). It forces the parser to write the current data over the first row of the image buffer, overwriting valid data and leaving the bottom of the image uninitialized.

Location: Lines 1890–1893.