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

execFile & Clamdscan result parsing #92

Closed Annubis45 closed 2 years ago

Annubis45 commented 2 years ago

On my configuration (Ubuntu 18.04.6 LTS, ClamAV 0.103.5), A scanfile lead to the execution of line 1555: execFile(command, (err, stdout, stderr) => { and lead to an error. Shouldn't it be: execFile(self.settings[self.scanner].path, self._buildClamArgs(items), (err, stdout, stderr) => {

when I do it its works better but I have another issue: The result of a clamdscan is :

/usr/bin/clamdscan --no-summary --fdpass --multiscan files/file1 files/file2 
/Code/files/file1: OK
/Code/files/file2: Win.Test.EICAR_HDB-1 FOUND

So, when it parse the result, line 1514:

                        let path = result.match(/^(.*): /);
                        if (path && path.length > 0) {
                            [path] = path;
                        } else {
                            path = '<Unknown File Path!>';
                        }

path equals to /Code/files/file2: with the char ' : '.

and just after, line 1522: if (/\s+OK(\u0000|[\r\n])$/.test(result)) { always return false. So all files seems to be infected.

my code:


        const clamscan = await new NodeClam().init({debugMode:true, scanRecursively: false}); // I tried with scanRecursively: true
        const version = await clamscan.getVersion();
        console.log(`ClamAV Version: ${version}`);
        clamscan.scanFiles(filesPath, (err, good_files, bad_files, viruses) => {
            console.log(good_files);
            console.log(bad_files);
            console.log(viruses);
           // console.log(err);
        });

Is my configuration wrong or outdated?

kylefarris commented 2 years ago

Looking into this.

kylefarris commented 2 years ago

Shouldn't it be: execFile(self.settings[self.scanner].path, self._buildClamArgs(items), (err, stdout, stderr) => {

Yes, it absolutely should, thank you!

kylefarris commented 2 years ago

New release v2.0.6 should fix your issue. Please let me know if it doesn't and we can re-open this issue.

Annubis45 commented 2 years ago

seems good, thanks a lot !