How I Found an Integer Overflow in ImageMagick Leading to Out-of-
An integer overflow in ImageMagick's TIM image parser on 32-bit systems causes a heap buffer under-allocation, leading to an out-of-bounds read. An attacker could craft a malicious TIM file to leak heap memory or cause a denial of service.
Published on medium.com
Hey there, security enthusiasts and fellow hackers! 🙂↔️ I’m Sumit Shah… Today, I’m excited to share a fresh finding: a High-severity integer overflow in ImageMagick that leads to an out-of-bounds read on 32-bit systems, potentially leaking sensitive heap memory.
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 write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code multiplies width and height without checking for integer overflow, so on 32-bit systems the result wraps around to a small value, causing under-allocation.
Impact
An attacker could leak heap memory or cause a denial of service by crashing the service; this only affects 32-bit systems.
What the attacker needed
32-bit system; ability to supply a crafted TIM file
The fix
The vulnerability was fixed in version 7.1.2-10 by validating dimensions against GetBlobSize and using safe casting.
How it was found
- Craft a TIM file with width and height set to 46341.
- The parser calculates image_size as 2 * width * height, which overflows 32-bit size_t and wraps to 18,506.
- The program allocates only 18,506 bytes for pixel data.
- The parser then loops over the original dimensions, reading far beyond the allocated buffer.
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 write-up has not been written yet. The Original tab links to the source.
ImageMagick is a tool that converts and processes images. When it reads a file, it calculates how much memory to reserve based on the image's width and height. On older 32-bit computers, a very large multiplication can wrap around to a small number, so the program reserves too little memory but then tries to read a huge image, causing it to read past the buffer and potentially expose data or crash.
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.