galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 169 forks source link

Hummus exception causes Node.js crashing #293

Closed vvsanil closed 1 year ago

vvsanil commented 6 years ago

Hi Gal,

We are using Node.js, It is crashing when we trying to process some PDFs. I have attached the sample for reference. We are getting the following error

" Unable to create form xobject from PDF page, parhaps the page index does not fit the total pages count "

After this error, When we try to end the PDF writer then the system crashing. I have tested in both Linux and Windows.

Here is the sample code

var pdfReader = hummus.createReader(src);
var pageCount = pdfReader.getPagesCount();
var pdfWriter = hummus.createWriter(dest, { version: hummus.ePDFVersion13 });
var cpyCxt = pdfWriter.createPDFCopyingContext(pdfReader);
for(var i=0;i<pdfReader.getPagesCount(); i++){
    var formID = cpyCxt.createFormXObjectFromPDFPage(i, hummus.ePDFPageBoxMediaBox);
    .............
    .............
}
pdfWriter.end();
[Sample.pdf](https://github.com/galkahana/HummusJS/files/2104945/Sample.pdf)

Please let me know how to handle this exception?

Thanks, Anil.

kilsen commented 5 years ago

We are experience the same issue -- we are attempting to read a PDF using createREader() (using PDFRStreamForBuffer) and if the PDF is corrupt, the call simply crashes Node.js. Is there a workaround? Is there a hummus method that will peek into a PDF and determine if it is valid or if it is corrupt?

through-a-haze commented 5 years ago

Same here. Using appendPDFPagesFromPDF with some PDFs (like this one) causes exception in Hummus and crashes Node.js app.

julianhille commented 2 years ago

Same here. Using appendPDFPagesFromPDF with some PDFs (like this one) causes exception in Hummus and crashes Node.js app.

Fixed this issue over in muhammara. https://github.com/julianhille/MuhammaraJS/pull/194

May the others check if that fixes their issues too?