Simple DirectMedia Layer SDL2_image IMG_LoadPCX_RW signed comparison code execution vulnerability
An integer overflow in SDL2_image's PCX loader allows a crafted file to cause a heap buffer overflow, potentially leading to code execution. An attacker can provide a malicious image file to trigger the vulnerability.
Originally disclosed on Cisco Talos
An exploitable integer overflow vulnerability exists when loading a PCX file in SDL2image 2.0.4. A specially crafted file can cause an integer overflow, resulting in too little memory being allocated, which 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 a signed integer comparison allows a negative bytes-per-line value to bypass a size check, which is then used as an unsigned size in a read operation, causing a heap buffer overflow.
Impact
An attacker could achieve remote code execution by controlling the size and content of the overwrite.
What the attacker needed
Victim opens a crafted PCX file
The fix
The vulnerability was fixed by the vendor.
How it was found
- Craft a PCX file with a large BytesPerLine value that causes bpl to become negative.
- Load the crafted PCX file using the vulnerable library.
- The negative bpl passes the check against surface->pitch.
- SDL_RWread is called with the negative bpl as size, leading to a huge read and buffer 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 calculates a size and checks it against another value. Because the numbers are signed, a negative size can pass the check and then be treated as a huge positive number, causing too much data to be written into a small buffer. This 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.