johnwhitington / cpdf-source

PDF Command Line Tools Source
GNU Affero General Public License v3.0
227 stars 26 forks source link

Malformed file leads to Stack overflow on writing #366

Open johnwhitington opened 2 weeks ago

johnwhitington commented 2 weeks ago

(In fact, on MacOS, a segmentation fault: why?)

$ cpdf 6.pdf -o out.pdf
couldn't lex object number
Because of error Pdf.PDFError("Bad xref stream whilst reading file 6.pdf at position 199"), will read as malformed.
Attempting to reconstruct the malformed pdf 6.pdf...
Unable to parse object:
Unable to parse object:
Read 2 objects
Malformed PDF reconstruction succeeded!
Segmentation fault: 11

This is presumably to do with object cycles.

6.pdf

yaoxixixi commented 2 weeks ago

I tried to debug with gdb and found that the space on the stack was constantly being taken up by loops and eventually causing it to overflow backtrace: 0x668841caml c call+25 0x63018f camlstdlib hashtbl find 887+95 0x59fe7b camlPdf lookup obj 879+43 0x5dad38 camlPdfpage fun 2205+120 0x60294b camlstdlib list rmap f 253+43 0x5dabd4 camlPdfpage find pages quick 174+276 0x60294b camlstdlib list rmap f 253+43 0x5dac36 camlPdfpage find pages quick 174+374