Skip to content

Fix heap-buffer-overflow read in TARGA RLE loader#39

Merged
danoli3 merged 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/targa-rle-oob-read
Apr 22, 2026
Merged

Fix heap-buffer-overflow read in TARGA RLE loader#39
danoli3 merged 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/targa-rle-oob-read

Conversation

@JorgeBarredo14
Copy link
Copy Markdown

Summary

When loading a malformed TGA file whose declared image dimensions exceed the actual remaining pixel data, the IOCache buffer size computed as (remaining_size / height) can be smaller than a single pixel. The RLE decoder then calls getBytes(file_pixel_size) and reads past the end of the undersized buffer.

Root cause

PluginTARGA.cpp line 596: const long sz = (remaining_size / height); — if remaining_size is small relative to height, sz can be less than file_pixel_size (e.g. 1 byte for a 24-bpp image that needs 3 bytes per pixel).

Fix

Clamp the cache size to at least file_pixel_size so that every getBytes call reads within bounds.

Metadata

  • CWE: CWE-122 (Heap-based Buffer Overflow)
  • Severity: High
  • Reproducer: 21-byte malformed TGA file (available on request)
  • Found during: academic security research
  • ASan trace: _assignPixel<24> at PluginTARGA.cpp:547, called from loadRLE<24> at line 651

@JorgeBarredo14
Copy link
Copy Markdown
Author

CI failures on macOS/clang are pre-existing — the same 4 checks fail on master (e.g. run on commit a750f88). This PR builds cleanly on Linux and Windows.

When loading a malformed TGA file whose declared image dimensions
exceed the actual remaining pixel data, the IOCache buffer size
computed as (remaining_size / height) can be smaller than a single
pixel. The RLE decoder then calls getBytes(file_pixel_size) and
reads past the end of the undersized buffer.

Ensure the cache size is at least file_pixel_size bytes so that
every getBytes call reads within bounds.

CWE-122 (Heap-based Buffer Overflow)
Found during academic security research.
@JorgeBarredo14 JorgeBarredo14 force-pushed the fix/targa-rle-oob-read branch from da5f07f to 68af81b Compare April 22, 2026 11:18
@danoli3 danoli3 merged commit 7816a57 into danoli3:master Apr 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants