Simple DirectMedia Layer SDL2_image ILBM CMAP Parsing Code Execution Vulnerability
The ILBM image parser in SDL2_image reads a chunk size value straight from the file and copies that many bytes into a fixed-size stack buffer for the colour map, without checking the length. A crafted ILBM image can therefore overflow the stack with attacker-controlled data and potentially lead to code execution when the image is displayed.
Originally disclosed on Cisco Talos
An exploitable code execution vulnerability exists in the ILBM image rendering functionality of SDL2image-2.0.2. A specially crafted ILBM image can cause a stack overflow resulting in code execution.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The chunk size read from the file is used directly as the copy length into a fixed-size stack colormap buffer with no bounds check.
Impact
A specially crafted image could cause a stack overflow and potentially code execution when displayed, though the report only demonstrates a crash under the debugger.
What the attacker needed
Victim opens or displays a crafted ILBM image
How it was found
- Open or display a specially crafted ILBM image with the vulnerable library.
- The parser reads a four-byte chunk size from the file and byte-swaps it.
- When a CMAP chunk is found, it copies that many bytes into the fixed-size colormap buffer on the stack.
- A size larger than the buffer overflows the stack with attacker-controlled data.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
An image file is made of labelled chunks, and each chunk starts with a number saying how long it is. The library trusted that number and copied that many bytes into a small fixed space on the stack, so a large number spills over into neighbouring memory. Because the attacker controls both the number and the bytes, they can overwrite important values and possibly run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.