kylefarris / clamscan

A robust ClamAV virus scanning library supporting scanning files, directories, and streams with local sockets, local/remote TCP, and local clamscan/clamdscan binaries (with failover).
MIT License
236 stars 69 forks source link

Fix undefined reference on an empty stream #37

Closed gobbard closed 5 years ago

gobbard commented 5 years ago

If an incoming stream is empty, the underlying Transform stream will call flush() without having called transform(). This results in the following error:

TypeError: uncaughtException: Cannot read property 'writable' of undefined
    at Transform.flush [as _flush] (/usr/src/app/node_modules/clamscan/index.js:1037:41)
    at Transform.prefinish (_stream_transform.js:141:10)
    at Transform.emit (events.js:198:13)
    at Transform.EventEmitter.emit (domain.js:466:23)
    at prefinish (_stream_writable.js:635:14)
    at finishMaybe (_stream_writable.js:643:5)
    at endWritable (_stream_writable.js:663:3)
    at Transform.Writable.end (_stream_writable.js:594:5)
    at FileStream.onend (_stream_readable.js:671:10)
    at Object.onceWrapper (events.js:286:20)
    at FileStream.emit (events.js:203:15)
    at FileStream.EventEmitter.emit (domain.js:466:23)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
kylefarris commented 5 years ago

This looks great! Thanks for providing the test as well--so many people forget to include that. I'm going to release this as 1.0.6.

kylefarris commented 5 years ago

1.0.6 has been officially released...