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).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Receiving null response from ScanFile

AishwaryaKotla opened this issue · comments

Team, I am receiving all the attributes as null in the response from the ScanFile method. Where as sending request via brew client to my server, i am getting a valid response. Could someone please help me on this. It might be some issue related to library or my configuration.

FYI: I am getting a valid response, when I use debugger mode and not in a normal mode. The configuration below is in nestjs.

package.json

"clamscan": "^2.1.2",
"@types/clamscan": "^2.0.4",

service.ts

import NodeClam = require('clamscan');

async scanFile(filePath: string) {
    try {
        const clamScan = new NodeClam().init({
            debugMode: true,
            clamdscan: {
                host: 'xxx',
                port: xxx,
                localFallback: false,
            },
        });
        const response = await (await clamScan).isInfected(filePath);
        return response;
    } catch (error) {
         console.error('Error occurred while scanning the file:', error);
         return false;
    }
}
  
async scanForVirus(excel: Express.Multer.File) {
    const result = await this.scanFile(excel.path);
    console.log(await result);
}

The result I am receiving is the below

node-clam: File may be INFECTED!
{
    file: null,
    isInfected: null,
    viruses: [],
    resultString: '',
    timeout: false
}

I see the below response using debugger when i tried to debug using breakpoints

{
    file: null,
    isInfected: false,
    viruses: [],
    resultString: 'OK',
    timeout: false
}

This might be happening due to the asynchronous operations running out of time in normal mode, where as in debug mode it might be having enough time to execute in between running the break points.

Could someone please let me know what might be causing the issue. Thanks in Advance.

Were you able to get the fix? I am also getting same error and trying to fix it.

I know it's been a while but I've got a couple things I noticed...

  1. You're doing import NodeClam = require('clamscan'); when it should be import NodeClam from 'clamscan'
  2. You should really just await the response from init instead of doing await (await clamScan).isInfected() -- that's just confusing/funky.

That being said, is your scanning service local or remote? If it's remote, it may be suffering from a timeout. You can increase the timeout with an optional config (timeout). The default is already 60 seconds, though. If you scanning very large files, you may need more. I suspect that's not the issue either, though, if you're thinking the difference in debugging or not is the difference in the timing.

All the tests seem to be working out just fine and I have several production servers running Ubuntu and AlmaLinux (RIP) that don't have this issue as well as my personal Mac for development. It's likely a code or configuration issue.