Simple DirectMedia Layer SDL2_image IMG_LoadPCX_RW code execution vulnerability
A heap-based buffer overflow occurs in SDL2_image's PCX loader because an error condition (bytes per line too large) is detected but not acted upon, allowing a crafted PCX file to write beyond the allocated surface buffer. An attacker could exploit this to achieve remote code execution.
Originally disclosed on Cisco Talos
An exploitable heap-based buffer overflow vulnerability exists when loading a PCX file in SDL2image, version 2.0.4. A missing error handler can lead to a buffer overflow and potential 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
Likely the code sets an error string when the calculated bytes per line exceeds the surface pitch but fails to abort or return, so the subsequent loop writes beyond the allocated buffer.
Impact
An attacker could potentially execute arbitrary code by controlling the size and content of the overwrite.
What the attacker needed
Victim opens a crafted PCX file
The fix
The error condition should be handled by aborting the load, for example by jumping to the cleanup code as done for other errors.
How it was found
- Craft a PCX file with a BytesPerLine value larger than the surface pitch.
- Load the malformed PCX file using the SDL2_image library.
- The library allocates a surface buffer based on image dimensions.
- During decoding, the loop writes past the end of the buffer, causing a heap overflow.
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.
When loading a PCX image, the library checks if a size value is too big and sets an error message, but then continues anyway. This lets a malicious image cause the program to write data past the end of a memory buffer, which can crash the program or let an attacker 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.