Foxit PDF Reader JavaScript getPageNumWords remote code execution vulnerability
Foxit PDF Reader's JavaScript engine contained a use-after-free: a crafted PDF could close the active document from inside a method call, leaving the method using a freed object. An attacker who got a victim to open the file could then run arbitrary code.
Originally disclosed on Cisco Talos
An exploitable use-after-free vulnerability exists in the JavaScript engine of Foxit Software’s Foxit PDF Reader version 9.1.0.5096. A specially crafted PDF document can trigger a previously freed object in memory to be reused, resulting in 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 getPageNumWords method called a user-supplied valueOf callback that could close the document and free objects, then continued using a stale reference to the freed object.
Impact
A crafted PDF could lead to arbitrary code execution, but the closeDoc call needs higher privileges, so the document must come from a trusted location or the user must approve a dialog; with the browser plugin enabled, visiting a malicious site could also trigger it.
What the attacker needed
Victim opens a crafted PDF; document trusted or user approves dialog; browser plugin enabled for web vector
The fix
The vendor patched the issue in a later release.
How it was found
- Create an object whose valueOf method closes the active document.
- Call getPageNumWords on the active document, passing that object as the argument.
- When the argument is converted, the document closes and objects are freed.
- The method resumes and dereferences the freed object, causing a crash that can be steered to code execution.
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.
A PDF can contain small programs written in JavaScript. This reader let such a program close the document while another part of the program was still using the document's data, so it carried on reading memory that had already been handed back. Because the attacker can influence what sits in that reused memory, they can redirect the program 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.