Giter VIP home page Giter VIP logo

Comments (3)

Maxwell2022 avatar Maxwell2022 commented on July 18, 2024

how do you run it in you node application?

from lambda-clamav-layer.

m-schrepel avatar m-schrepel commented on July 18, 2024

This appears to happen when you run the command with child_process.exec, but not childProcess.spawn

// doesn't work

    fs.writeFileSync('/tmp/bs.txt', 'hello world!', { encoding: 'utf8' })
    const file = fs.readFileSync('/tmp/bs.txt', 'utf8')
    console.log('file contents', file)

    const scan = execSync('clamscan /tmp/bs.txt')
    console.log('scan status', scan.status);
    console.log(scan.stdout.toString());

produces:

{
  "errorType": "Error",
  "errorMessage": "Command failed: clamscan /tmp/bs.txt\nLibClamAV Error: cl_load(): No such file or directory: /var/clamav\nERROR: Can't get file status\n",
  "trace": [
    "Error: Command failed: clamscan /tmp/bs.txt",
    "LibClamAV Error: cl_load(): No such file or directory: /var/clamav",
    "ERROR: Can't get file status",
    "",
    "    at checkExecSyncError (child_process.js:616:11)",
    "    at execSync (child_process.js:652:15)",
    "    at Runtime.exports.handler (/var/task/index.js:10:18)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

// works kinda

    const spawnSync = require('child_process').spawnSync;

    fs.writeFileSync('/tmp/bs.txt', "hello world!", { encoding: 'utf8' })
    const file = fs.readFileSync('/tmp/bs.txt', 'utf8')
    console.log('file contents:', file)

    const scan = spawnSync('clamscan', ['', '/tmp/bs.txt'], {
        stdio: 'pipe',
        stderr: 'pipe'
    });
    console.log('scan status', scan.status);
    console.log(scan.stdout.toString());

produces:

Function Logs
START RequestId: 6a8d44a4-1113-4c1a-8e58-c4ddb9853cc9 Version: $LATEST
2021-02-04T03:06:03.457Z	6a8d44a4-1113-4c1a-8e58-c4ddb9853cc9	INFO	file contents: hello world!
2021-02-04T03:06:04.598Z	6a8d44a4-1113-4c1a-8e58-c4ddb9853cc9	INFO	scan status 2
2021-02-04T03:06:04.617Z	6a8d44a4-1113-4c1a-8e58-c4ddb9853cc9	INFO	
----------- SCAN SUMMARY -----------
Known viruses: 0
Engine version: 0.102.4
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 0.380 sec (0 m 0 s)

from lambda-clamav-layer.

tktwong avatar tktwong commented on July 18, 2024

Hi all,
Implement the same approach as m-schrepel but still got "No such file or directory"
//My codes
const scanStatus: SpawnSyncReturns<Buffer> = spawnSync('clamscan', ['--database=/opt/var/lib/clamav',/tmp/${record.s3.object.key}], { stdio: 'pipe', encoding: 'buffer', }); console.log('scanStatus', scanStatus); console.log('stdout', scanStatus.stdout.toString()); console.log('stderr', scanStatus.stderr.toString()); scanStatus.output.forEach(item => console.log(item && item.toString()));

//scanStatus
37772a93-7eb3-4de5-aae4-979e26d2232f INFO scanStatus { status: 2, signal: null, output: [ null, <Buffer 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 53 43 41 4e 20 53 55 4d 4d 41 52 59 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 4b 6e 6f 77 6e 20 76 69 72 75 73 65 ... 233 more bytes>, <Buffer 4c 69 62 43 6c 61 6d 41 56 20 45 72 72 6f 72 3a 20 63 6c 5f 6c 6f 61 64 28 29 3a 20 4e 6f 20 73 75 63 68 20 66 69 6c 65 20 6f 72 20 64 69 72 65 63 74 ... 54 more bytes> ], pid: 24, stdout: <Buffer 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 53 43 41 4e 20 53 55 4d 4d 41 52 59 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 4b 6e 6f 77 6e 20 76 69 72 75 73 65 ... 233 more bytes>, stderr: <Buffer 4c 69 62 43 6c 61 6d 41 56 20 45 72 72 6f 72 3a 20 63 6c 5f 6c 6f 61 64 28 29 3a 20 4e 6f 20 73 75 63 68 20 66 69 6c 65 20 6f 72 20 64 69 72 65 63 74 ... 54 more bytes> }

//stdout
37772a93-7eb3-4de5-aae4-979e26d2232f INFO stdout ----------- SCAN SUMMARY -----------Known viruses: 0Engine version: 0.103.5Scanned directories: 0Scanned files: 0Infected files: 0Data scanned: 0.00 MBData read: 0.00 MB (ratio 0.00:1)Time: 0.021 sec (0 m 0 s)Start Date: 2022:04:08 08:42:12End Date: 2022:04:08 08:42:12 | 2022-04-08T08:42:12.612Z 37772a93-7eb3-4de5-aae4-979e26d2232f INFO stdout ----------- SCAN SUMMARY ----------- Known viruses: 0 Engine version: 0.103.5 Scanned directories: 0 Scanned files: 0 Infected files: 0 Data scanned: 0.00 MB Data read: 0.00 MB (ratio 0.00:1) Time: 0.021 sec (0 m 0 s) Start Date: 2022:04:08 08:42:12 End Date: 2022:04:08 08:42:12

//stderr
37772a93-7eb3-4de5-aae4-979e26d2232f INFO stderr LibClamAV Error: cl_load(): No such file or directory: /opt/var/lib/clamav ERROR: Can't get file status

from lambda-clamav-layer.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.