SDL_image XPM image color code code execution vulnerability
The XPM image parser in SDL2_image multiplies the number of colours by the characters per pixel to size a buffer, and that multiplication can overflow so a much smaller buffer is allocated. A crafted XPM image then causes an out-of-bounds heap write, which the report says can lead to code execution.
Originally disclosed on Cisco Talos
An exploitable code execution vulnerability exists in the XPM image rendering functionality of SDL2image 2.0.4. A specially crafted XPM image can cause an integer overflow, allocating too small of a buffer.
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 allocation size is computed as ncolors * cpp without checking for integer overflow, so a wrapped small size is later overrun by a memcpy of cpp bytes.
Impact
A specially crafted image could cause a heap overflow and potentially code execution when displayed, though the report only demonstrates a crash under AddressSanitizer.
What the attacker needed
Victim opens a crafted XPM image; application uses SDL2_image 2.0.4
The fix
The allocation should be checked for integer overflow, and the vendor patched the issue.
How it was found
- Craft an XPM image whose header gives a very large number of colours and characters per pixel.
- Open the image so the library parses the header and allocates the undersized buffer.
- Supply colour definition lines so the parser copies data into that buffer.
- The copy writes past the end of the heap buffer and the process crashes or is corrupted.
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 library reads a small text header that says how many colours the image has and how many characters describe each pixel. It multiplies those two numbers to decide how much memory to reserve, but the multiplication can wrap around to a tiny number, so the program then writes far more data than it reserved. That memory corruption can let an attacker run their own code when the image is opened.
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.