OpenImageIO TGA Format Stack Buffer Overflow Vulnerability
A stack-based buffer overflow in OpenImageIO's TGA parser allows a crafted TGA file to cause out-of-bounds reads and writes, potentially leading to arbitrary code execution. The vulnerability arises because a fixed-size buffer is filled without null termination, and subsequent string operations can read or write beyond its bounds.
Originally disclosed on Cisco Talos
A stack-based buffer overflow vulnerability exists in the TGA file format parser of OpenImageIO v2.3.19.0. A specially-crafted targa file can lead to out of bounds read and write on the process stack, which can lead to arbitrary code execution.
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 reads file data into a fixed-size stack buffer without ensuring null termination, then uses string functions like strlen and sprintf that can access memory beyond the buffer.
Impact
A crafted TGA file could cause out-of-bounds reads and writes on the stack, potentially leading to arbitrary code execution, though the exact impact depends on compilation and the current master branch only allows out-of-bounds reads.
What the attacker needed
Victim opens a malicious TGA file
How it was found
- Open a crafted TGA file with OpenImageIO.
- The parser reads the header and detects a TGA 2.0 extension area with size >= 495.
- It reads the extension area fields into a 324-byte stack buffer without null termination.
- Later, it reads the software field and uses strlen on the non-terminated buffer, causing an out-of-bounds read.
- A sprintf then writes past the buffer, causing an out-of-bounds write.
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 a file, it often copies data into a fixed-size memory area. If the data isn't properly ended with a special zero byte, later operations that expect a text string can read or write past the end of that area, corrupting other data. Here, a malicious image file can trigger this, 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.