GHSL-2020-142: Heap memory corruption in png-img - CVE-2020-28248
The png-img package's native bindings allocate memory for PNG image data using a 32-bit multiplication of height and rowbytes, which can overflow and cause an undersized heap allocation. An attacker could supply a crafted PNG to overwrite adjacent heap memory with controlled data, potentially leading to arbitrary code execution.
Originally disclosed on GitHub Security Lab
The png-img package provides NAN bindings for libpng. These bindings are vulnerable to an integer overflow which results in an underallocation of heap memory and subsequent heap memory corruption.
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 code multiplies two 32-bit unsigned integers (height and rowbytes) without checking for overflow, leading to an undersized allocation.
Impact
This issue may lead to arbitrary code execution if png-img is used to operate on untrusted PNG files.
What the attacker needed
Png-img used on untrusted PNG files
The fix
The maintainer prepared a pull request that fixes the integer overflow and upgrades the libpng version, and released version 3.1.0.
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 loads an image, it calculates how much memory to reserve by multiplying the image's height by the number of bytes per row. If that multiplication is done with limited-size numbers, the result can wrap around to a small value, so the program reserves too little memory. Later, when it writes the image data, it can spill over into other memory, which an attacker might exploit to 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.