Simple DirectMedia Layer SDL2_Image LWZ Decompression Buffer Overflow Vulnerability
A buffer overflow in SDL2_image's GIF parsing allows a crafted GIF to write past a global buffer, potentially causing a crash or other undefined behaviour. An attacker can trigger this by displaying a malicious image.
Originally disclosed on Cisco Talos
A buffer overflow vulnerability exists in the GIF image parsing functionality of SDL2image-2.0.2. A specially crafted GIF image can lead to a buffer overflow on a global section.
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 LZW decompression loop does not properly validate table entries, allowing a circular reference that causes an infinite loop and out-of-bounds write to the static stack buffer.
Impact
The out-of-bounds write occurs in the global data section and is limited to writing valid LZW code values, which could crash the application or potentially corrupt other global variables, but not directly lead to code execution.
What the attacker needed
Victim opens a crafted GIF; application uses SDL2_image
How it was found
- Craft a GIF image with a specially crafted LZW-compressed data stream that creates a circular table entry.
- Open or display the crafted GIF using an application that uses SDL2_image.
- The LZW decompression loop fails to terminate, causing an out-of-bounds write and a crash.
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 a program reads a GIF image, it decompresses the image data into a buffer. A bug in the decompression code lets a malicious GIF cause the program to write data past the end of that buffer, which can crash the program or corrupt memory. This happens because the code fails to stop a loop that keeps writing to the buffer.
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.