Skip to content

Fix heap-buffer-overflow write in CUT RLE parser#40

Open
JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/cut-rle-oob-write
Open

Fix heap-buffer-overflow write in CUT RLE parser#40
JorgeBarredo14 wants to merge 1 commit intodanoli3:masterfrom
JorgeBarredo14:fix/cut-rle-oob-write

Conversation

@JorgeBarredo14
Copy link
Copy Markdown

Summary

The CUT (Dr. Halo) format parser allocates a bitmap from the file header (width * height). During RLE decompression, a zero-count byte triggers bits -= pitch to move to the previous scanline. If the header declares height=1 but the RLE data contains multiple zero-count markers, the scanline pointer underflows below the heap allocation, causing an out-of-bounds write on the subsequent memset or read_proc call.

Root cause

PluginCUT.cpp line 169: bits -= pitch; — no check that bits remains within the allocated bitmap before decrementing.

Fix

Add a bounds check before the decrement: verify that bits is at least pitch bytes above the start of the bitmap data. If not, break out of the decompression loop.

Metadata

  • CWE: CWE-787 (Out-of-bounds Write)
  • Severity: Critical (CVSS 8.8)
  • Reproducer: 24-byte CUT file with width=0x230B, height=0x0001 (available on request)
  • Found during: academic security research
  • ASan trace: SEGV via memcpy at PluginCUT.cpp:193, triggered by _MemoryReadProc

When decompressing a CUT (Dr. Halo) format image, a zero-count
byte in the RLE stream causes the scanline pointer to be
decremented (bits -= pitch) without verifying that the pointer
remains within the allocated bitmap. If the header declares
height=1 but the RLE data contains multiple zero-count markers,
the pointer underflows below the heap allocation, leading to an
out-of-bounds write via the subsequent memset or read_proc call.

Add a bounds check before the decrement to ensure the pointer
does not move past the first scanline.

CWE-787 (Out-of-bounds Write)
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