LibRaw deflate_dng_load_raw integer overflow vulnerability
An integer overflow in LibRaw's deflate-compressed DNG decoder causes a heap buffer overflow when tile dimensions are attacker-controlled. An attacker could provide a malicious DNG file to corrupt heap memory, potentially leading to code execution, but only if the application raises the memory limit above the default.
Originally disclosed on Cisco Talos
An integer overflow vulnerability exists in the deflatedngloadraw functionality of LibRaw Commit 8dc68e2. A specially crafted malicious file can lead to a heap buffer overflow.
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 size calculation for the memory limit check and buffer allocation multiplies several 32-bit values before assigning the result to a 64-bit variable, so the product can overflow and wrap around.
Impact
This heap buffer overflow could result in heap corruption and potential code execution, but only for applications that raise max_raw_memory_mb above the default; the default limit blocks exploitation.
What the attacker needed
Application raises max_raw_memory_mb above default; attacker supplies a crafted DNG file
How it was found
- Craft a tiled DNG file with large ImageWidth, ImageLength, TileWidth, TileHeight and SamplesPerPixel values.
- Ensure the application's max_raw_memory_mb is set high enough to pass the pre-decoder memory check.
- Open the file with LibRaw, which calls unpack() and then deflate_dng_load_raw().
- The 32-bit multiplication overflows, so the memory limit check passes and an undersized buffer is allocated.
- The decoding loop writes tile data beyond the allocated buffer, causing a heap 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.
LibRaw is a library for reading RAW image files. A maths mistake when calculating how much memory to reserve for a compressed image means a malicious file can make the program write past the end of a reserved memory area, which can crash it or let an attacker run their own code. However, the default memory limit blocks this unless an application has raised that limit.
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.