SAIL Image Decoding Library WebP Image Decoding integer overflow vulnerability
An integer overflow when calculating the canvas buffer size for a crafted animated WebP image causes an undersized heap allocation, which is then overrun when the background colour is written. An attacker could achieve heap-based buffer overflow and potentially remote code execution by getting the library to decode a malicious file.
A memory corruption vulnerability exists in the WebP Image Decoding functionality of the SAIL Image Decoding Library v0.9.8. When loading a specially crafted .webp animation an integer overflow can be made to occur when calculating the stride for decoding.
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 canvas size is computed as a 32-bit product of stride and height without an overflow check, so a large animated WebP yields a tiny allocation that is then written to as if it were full size.
Impact
On 32-bit platforms the overflow can corrupt the heap and could allow remote code execution in the context of the library, though the attacker must first get the library to read a crafted file.
What the attacker needed
32-bit platform; victim opens a crafted .webp file
The fix
The size calculation should be performed in a wider type with an overflow check before allocating, and the vendor released a patch.
How it was found
- Create a WebP file whose VP8X chunk sets the animation flag and declares very large canvas dimensions.
- Add an ANIM chunk carrying the background colour and an ANMF chunk with frame data.
- Run the library's decode command on the crafted file.
- Observe the heap-buffer-overflow reported by AddressSanitizer in the background fill routine.
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 works out how much memory to reserve for a picture by multiplying its width, height and bytes per pixel. With a huge animated image those numbers wrap around and produce a tiny reservation, so when the library fills the picture with a background colour it writes past the end of that small block of memory. Writing past reserved memory 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.