*Fuzzing a C-Based PDF Parser with AFL++
A C-based PDF parser had a stack buffer overflow because a dynamic array was initialised with the wrong element size, causing a copy to overflow a stack structure. An attacker could supply a malformed PDF to crash the parser or potentially execute arbitrary code.
medium.com
Published on medium.com
Fuzzing is a widely used automated technique for finding vulnerabilities in software by providing unexpected or random inputs to a program. The main objective is to identify potential bugs or security flaws, such as memory corruption, by pushing the software to handle inputs that it would not normally expect.
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 dynamic array for PDF objects was initialised with the size of the wrong structure type, so a later copy used a larger size than the destination buffer, causing a stack overflow.
Impact
The stack buffer overflow could allow an attacker to execute arbitrary code or crash the parser, leading to remote code execution or denial of service.
What the attacker needed
Malformed PDF file; parser processes the file
The fix
The parser should initialise the dynamic array with the correct structure size and allocate objects on the heap before appending them.
How it was found
- Compile the PDF parser with AddressSanitizer and AFL++ instrumentation.
- Prepare a directory of sample PDF files as initial inputs.
- Run AFL++ against the compiled parser binary.
- Observe crashes and collect the crashing inputs.
- Analyse a crash in IDA to locate the overflow in the copy operation.
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.
A PDF parser reads PDF files. A stack buffer overflow happens when a program writes more data into a small memory area than it can hold, which can crash the program or let an attacker run their own code. Here, the parser used the wrong size when copying data, so a malformed PDF could overflow a buffer on the stack.
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.