Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanDir do not return an array of files #87

Closed
Annubis45 opened this issue Feb 14, 2022 · 10 comments
Closed

scanDir do not return an array of files #87

Annubis45 opened this issue Feb 14, 2022 · 10 comments
Labels

Comments

@Annubis45
Copy link
Contributor

The result of doesn't return arrays of good files and bad files.
It returns an array with the path scanned.

@kylefarris
Copy link
Owner

Please refer to the docs: https://github.com/kylefarris/clamscan#note

Relevant passage:

The goodFiles and badFiles parameters of the end_callback callback in this method will only contain the directories that were scanned in all but the following scenarios:

  • A file_callback callback is provided, and scanRecursively is set to true.
  • The scanner is set to clamdscan and scanRecursively is set to false.

@kylefarris kylefarris added the not a bug For bugs reported that are not specific to this module. label Feb 14, 2022
@Annubis45
Copy link
Contributor Author

Hi,

Here my code:

        console.log('AnalyseFiles:');
        const clamscan = await new NodeClam().init({ scanRecursively: false});
        const version = await clamscan.getVersion();
        console.log(`ClamAV Version: ${version}`);


        clamscan.scanDir('./files/', (err, goodFiles, badFiles, viruses) => {
            if (err) return console.error(err);
        
            if (badFiles.length > 0) {
                console.log(`${path} was infected. The offending files (${badFiles.join (', ')}) have been quarantined.`);
                console.log(`Viruses Found: ${viruses.join(', ')}`);
            } else {
                console.log("Everything looks good! No problems here!.");
            }
        },
        (error, file, isInfected) =>{
            console.log(`${file} is ${isInfected ? 'infected' : 'clean'}`);
        });

and the result is :

ClamAV Version: ClamAV 0.103.5/26459/Sun Feb 20 10:22:37 2022
Attachment is infected
ContentVersion is infected
Everything looks good! No problems here!

files directory is :
---files
----- Attachment
-----------file1
-----------file2
-----------file3
----- ContentVersion
-----------file4
-----------file5

@kylefarris
Copy link
Owner

You would need to set scanRecursively to true if you want to see the individual files that are infected.

@Annubis45
Copy link
Contributor Author

Thank you for your answser.

When I set scanRecursively to true, I get this error:

node_modules/clamscan/index.js:1529
    if (err) return hasCb ? endCb(err, goodFiles, badFiles,viruses, []) : reject(new NodeClamError({ badFiles }, err));

@kylefarris
Copy link
Owner

That can't be the entire error. That's just the stacktrace showing where the error was thrown. I'd need to know what error was actually thrown here as the could be any number of things.

@Annubis45
Copy link
Contributor Author

Annubis45 commented Mar 7, 2022

Hi,

I restarted eveything from scratch:

my code:

console.log('AnalyseFiles:');
const clamscan = await new NodeClam().init({ debugMode:true, scanRecursively: true});
const version = await clamscan.getVersion();
console.log(`ClamAV Version: ${version}`);
clamscan.scanDir('./filesdir/', (err, goodFiles, badFiles, viruses) => {
        if (err) return console.error(err);
    
        if (badFiles.length > 0) {
            console.log(`MYLOG -  it was infected. The offending files (${badFiles.join (', ')}) have been quarantined.`);
            console.log(`MYLOG - Viruses Found: ${viruses.join(', ')}`);
        } else {
            console.log("MYLOG - Everything looks good! No problems here!.");
        }
    },
    (error, file, isInfected) =>{
        console.log(`MYLOG - ${file} is ${isInfected ? 'infected' : 'clean'}`);
    });

My directory :
---filesdir
----- rep1
-----------file1
----- rep2
-----------file1
-----------file2

And the result:

node-clam: DEBUG MODE ON
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan --version
ClamAV Version: ClamAV 0.103.5/26473/Sun Mar  6 10:27:13 2022

node-clam: Scanning a list of 6 passed files. [
  'filesdir',
  'filesdir/rep1',
  'filesdir/rep1/file1',
  'filesdir/rep2',
  'filesdir/rep2/file1',
  'filesdir/rep2/file2'
]
node-clam: Scanning filesdir/rep1/file1
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir/rep1/file1
node-clam: Scanning filesdir/rep2/file1
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir/rep2/file1
node-clam: Scanning filesdir/rep2/file2
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir/rep2/file2
node-clam: Scanning a list of 2 passed files. [ 'filesdir/rep1', 'filesdir/rep1/file1' ]
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir/rep1 filesdir/rep1/file1
node-clam: Scanning a list of 6 passed files. [
  'filesdir',
  'filesdir/rep1',
  'filesdir/rep1/file1',
  'filesdir/rep2',
  'filesdir/rep2/file1',
  'filesdir/rep2/file2'
]
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir filesdir/rep1 filesdir/rep1/file1 filesdir/rep2 filesdir/rep2/file1 filesdir/rep2/file2
node-clam: Scan Response:  /filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND
node-clam: File is INFECTED!
node-clam: File is OK!
node-clam: File is OK!
node-clam: Scanning a list of 3 passed files. [ 'filesdir/rep2', 'filesdir/rep2/file1', 'filesdir/rep2/file2' ]
node-clam: Configured clam command: /usr/bin/clamdscan --no-summary --fdpass --multiscan filesdir/rep2 filesdir/rep2/file1 filesdir/rep2/file2
node-clam: stdout: /filesdir/rep1: OK
/filesdir/rep1/file1: OK

node-clam: /filesdir/rep1 is OK!
node-clam: /filesdir/rep1/file1 is OK!
node-clam: stdout: /filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND
/filesdir/rep2/file1: OK
/filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND

node-clam: /filesdir/rep2/file2 is INFECTED!
node-clam: /filesdir/rep2/file1 is OK!
node-clam: /filesdir/rep2/file2 is INFECTED!
node-clam: stdout: /filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND
/filesdir/rep1: OK
/filesdir/rep1/file1: OK
/filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND
/filesdir/rep2/file1: OK
/filesdir/rep2/file2: Win.Test.EICAR_HDB-1 FOUND

node-clam: /filesdir/rep2/file2 is INFECTED!
node-clam: /filesdir/rep1 is OK!
node-clam: /filesdir/rep1/file1 is OK!
node-clam: /filesdir/rep2/file2 is INFECTED!
node-clam: /filesdir/rep2/file1 is OK!
node-clam: /filesdir/rep2/file2 is INFECTED!

And when I put breakpoints in callback functions, I never reach it.

I also tried the promise syntaxe and stay stuck in it. I got the same result and never reach the next line.

const {goodFiles, badFiles} = await clamscan.scanDir('./filesdir/');

I'm sorry if this thread has changed since the start. If you want I can open a new one.

@Annubis45
Copy link
Contributor Author

My analyse is :
scandir need a resolve/reject result, but when I call it with my option, it does:
scandir ==> scanFiles ==> doscan ==> ...

Scandir return a promise that make a "return scanfile(...)" and scanfile return a promise (line 1978)
So, my guess is the promise of scandir is never resolved.

line 1978 :
return this.scanFiles(files, endCb, fileCb);

IMO, it should be replaced by something like this:

const scanResult= await this.scanFiles(files, endCb, fileCb);
return hasCb
        ? endCb(null, [], [])
        : resolve(scanResult);

@kylefarris
Copy link
Owner

That's more like it. Yeah, from looking at your debug log, it all looks like it's working up to a point. I haven't had a chance to look at the source code yet but your analysis seems correct in theory. Why don't you see if you can fix the issue and run some tests? A PR would be really help since I'm quite busy this week.

Thanks for all your hard work.

@Annubis45
Copy link
Contributor Author

ok, I'll try !

@kylefarris kylefarris added bug and removed not a bug For bugs reported that are not specific to this module. labels Mar 8, 2022
@kylefarris
Copy link
Owner

FTR, this issue was fixed in v2.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants