SAIL Image Decoding Library BMPv3 Palette Decoding integer overflow vulnerability
An integer overflow in the BMPv3 palette decoding of the SAIL image library can cause a heap-based buffer overflow when a crafted .bmp file is loaded. This could allow remote code execution if an attacker convinces the library to read a malicious file.
A memory corruption vulnerability exists in the BMPv3 Palette Decoding functionality of the SAIL Image Decoding Library v0.9.8. When loading a specially crafted .bmp file, an integer overflow can be made to occur which will cause a heap-based buffer to overflow when reading the palette from the image.
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 palette count from the file is multiplied by the pixel size without checking for integer overflow, leading to an undersized allocation.
Impact
This could allow remote code execution within the context of the library, but only on 32-bit platforms where the integer overflow occurs.
What the attacker needed
32-bit platform; victim loads a crafted .bmp file
How it was found
- Craft a BMP file with a v3 or later header and a bit count less than 16.
- Set the colors_used field to a large value so that multiplying by 4 overflows 32 bits.
- Load the crafted file with the SAIL library.
- The library allocates a small buffer and then writes palette entries beyond its bounds.
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 an image file, it uses numbers from the file to decide how much memory to set aside. If those numbers are multiplied and the result is too big for the computer to store in the expected space, the calculation wraps around to a small number, so too little memory is reserved. The program then writes more data than fits, corrupting memory and potentially letting 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.