galkahana / HummusJS

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

electron crash, needs at least input validation for pdfstreamresponse #439

Closed julianhille closed 2 years ago

julianhille commented 4 years ago

"electron": "4.2.9", "hummus": "^1.0.105",

Reproduce is as simple as this:

  hummus = require('hummus')
  writer = new hummus.PDFStreamForResponse(null)
  writer = hummus.createWriter(writer)
  writer.end()

The object PDFStreamForResponse does take ANYTHING as value. This later will be used to write the header to int and so goes through WriteComment in hummus.

The node/electron call to v8:V8:toLocalEmpty kills it and jumps bad in memory.

Parts of the stack to follow:


Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   com.github.Electron.framework   0x00000001069702f0 0x104c13000 + 30790384
1   com.github.Electron.framework   0x0000000106397560 v8::V8::ToLocalEmpty() + 64
2   hummus.node                     0x000000010e2fcff1 ObjectByteWriterWithPosition::Write(unsigned char const*, unsigned long) + 615
3   hummus.node                     0x000000010e33cfed ObjectsContext::WriteComment(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 35
4   hummus.node                     0x000000010e320c49 PDFHummus::DocumentContext::WriteHeader(EPDFVersion) + 23
5   hummus.node                     0x000000010e2f34bc PDFWriterDriver::StartPDF(v8::Local<v8::Object>, EPDFVersion, LogConfiguration const&, PDFCreationSettings const&) + 90
6   hummus.node                     0x000000010e2fdfc4 CreateWriter(v8::FunctionCallbackInfo<v8::Value> const&) + 2778```

Could be easily fixed if at leasdt some null / undefined checks are done here.
julianhille commented 2 years ago

https://github.com/julianhille/MuhammaraJS/issues/188