node-mbox icon indicating copy to clipboard operation
node-mbox copied to clipboard

Large Message Crash

Open tpreusse opened this issue 8 years ago • 1 comments

If a message is bigger than the V8 string length limit (Math.pow(2, 28), ~260mb) the parser will crash with following error:

node_modules/node-mbox/src/mbox.js:100
        stream.emit('message', 'From ' + chunks.join(''));
                                                ^

RangeError: Invalid string length
    at Array.join (native)
    at SBMH.<anonymous> (node_modules/node-mbox/src/mbox.js:100:49)
    at emitMany (events.js:146:13)
    at SBMH.emit (events.js:223:7)
    at SBMH._sbmh_feed (node_modules/streamsearch/lib/sbmh.js:159:14)
    at SBMH.push (node_modules/streamsearch/lib/sbmh.js:56:14)
    at MboxStream._transform (node_modules/node-mbox/src/mbox.js:119:17)
    at MboxStream.Transform._read (_stream_transform.js:186:10)
    at MboxStream.Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:387:12)

A potential mitigation strategy: https://gist.github.com/tpreusse/bc2ccf6fc6bf4ff563cdd336c1728db2/revisions#diff-05028f8355c8d7379cb42b5feac6429f (throw error by default, skip or emit partial via options)

However the ultimate solution would be create a new api which allows to stream junks (e.g. to mailparser) as they come in. mailparser can probably handle almost unlimited attachment sizes with its attachment streams.

tpreusse avatar Nov 07 '17 23:11 tpreusse

Perhaps it's easiest to create an option that, instead of emitting a message string (for the message event), it would emit a message stream, which could subsequently be passed to mailparser.

I'll have a think about it (busy with other projects at the moment) and see if I can come up with something.

robertklep avatar Nov 08 '17 11:11 robertklep