DCMTK — Vulnerability Report
When XMLNode::parseFile() is given a FIFO as input, ftell() returns -1, which the code fails to reject, so a tiny heap buffer is allocated and a huge read is attempted. An attacker who can supply a FIFO path could corrupt heap memory and crash or potentially execute code in the cda2dcm tool.
medium.com
Published on medium.com
https://github.com/DCMTK/dcmtk/commit/1d4b3815c0987840a983160bfc671fef63a3105b
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
Likely the return value of ftell() was not checked for the error value -1 before being used as a buffer size and read length.
Impact
The overflow could corrupt adjacent heap memory, leading to a crash and potentially code execution, though the proof of concept only demonstrates a crash under AddressSanitizer.
What the attacker needed
Local access to run cda2dcm; ability to supply a FIFO as input; build with AddressSanitizer to see crash
The fix
The code should reject a negative size returned by ftell() before allocating or reading, as the linked commit presumably does.
How it was found
- Create a named pipe to act as the input file.
- Start cda2dcm with that pipe as the input and an output file.
- Write a small XML document into the pipe from another terminal.
- Observe the AddressSanitizer heap-buffer-overflow report.
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 named pipe is a special file that streams data instead of storing it, so the program cannot ask how big it is. The code asked for the size, got an error value of minus one, and treated it as a real size, so it made a tiny buffer and then tried to pour an enormous amount of data into it. That overflows memory next to the buffer and can crash the program or let an attacker take control.
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.