Skip to content

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

Open
JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/targa-rle-oob-read
Open

Fix heap-buffer-overflow read in TARGA RLE loader#39
JorgeBarredo14 wants to merge 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

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.
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.

1 participant