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
232 stars 67 forks source link

3.8 GB file gives issue - RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range #81

Open nitinrgoyal opened 2 years ago

nitinrgoyal commented 2 years ago

Using latest version of clamscan, I am getting the following error when I try to load a 3.8 GB file.

node-clam: Provided stream is readable. node-clam: Attempting to establish socket/TCP connection for "scanStream" node-clam: using local unix domain socket: /var/run/clamav/clamd.ctl internal/buffer.js:69 throw new ERR_OUT_OF_RANGE('value', range, value); ^

RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 3875796802 at checkInt (internal/buffer.js:69:11) at writeU_Int32BE (internal/buffer.js:799:3) at Buffer.writeInt32BE (internal/buffer.js:887:10) at NodeClamTransform._transform (/home/repo-l2/Documents/projects/ge-clam/node_modules/clamscan/lib/NodeClamTransform.js:44:14) at NodeClamTransform.Transform._read (internal/streams/transform.js:205:10) at NodeClamTransform.Transform._write (internal/streams/transform.js:193:12) at writeOrBuffer (internal/streams/writable.js:358:12) at NodeClamTransform.Writable.write (internal/streams/writable.js:303:10) at Readable.ondata (internal/streams/readable.js:726:22) at Readable.emit (events.js:375:28) { code: 'ERR_OUT_OF_RANGE' }

kylefarris commented 2 years ago

It seems like the buffer is filling up faster than it can be offloaded to the downstream target. Can you share the relevant part of your code?

project-administrator commented 2 years ago

No, it's writeInt32BE function failing in one of these places: https://github.com/kylefarris/clamscan/search?q=writeInt32BE

It cannot process value bigger than 4 bytes signed integer:

⋊> ~ node                                                                                        07:41:17
Welcome to Node.js v16.9.1.
Type ".help" for more information.
> const size = Buffer.alloc(4);
undefined
> size.writeInt32BE(2442710324, 0);
Uncaught:
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 2442710324
    at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
    at new NodeError (node:internal/errors:371:5)
    at checkInt (node:internal/buffer:72:11)
    at writeU_Int32BE (node:internal/buffer:802:3)
    at Buffer.writeInt32BE (node:internal/buffer:890:10) {
  code: 'ERR_OUT_OF_RANGE'
}