Limits and tuning
A scanner is handed files chosen by an attacker, so every stage is bounded. The
bounds measure different things, and reaching any of them produces
LIMITS-EXCEEDED rather than a clean result, unless
--partial-as says
otherwise.
The in-core budgets
Section titled “The in-core budgets”These act first, and they are the ones that produce a verdict. The engine field
column is for library users (Limits in exav-unpack,
ScanOptions in exav-core).
| CLI flag | Engine field | Default | What it stops |
|---|---|---|---|
--max-input-bytes |
ScanOptions::max_scan_size |
no limit | A top-level input too big to take whole (its first bytes still get the whole scan) |
--max-object-bytes |
Limits::max_buffer_bytes (ScanOptions::limits) |
256 MiB | The largest single object held in memory; a larger file or member is read through a block cache or a temporary file. Also the PDF object table of bytecode and a GPT entry array |
--max-matcher-bytes |
Limits::max_scanned_bytes |
10 GiB | Cumulative bytes fed to the matcher |
--max-hole-bytes |
Limits::max_hole_bytes |
64 GiB | Cumulative bytes of holes (the unwritten stretches of sparse files in a filesystem image) fed to the matcher as zeros; they count here and not toward --max-matcher-bytes |
--max-pcre-bytes |
ScanOptions::max_pcre_bytes |
no limit (100 MiB under --clamav-compat) |
PCRE subsignatures on an object larger than this, which then do not match; the scan is reported incomplete, except under --clamav-compat |
--max-regex-steps |
ScanOptions::max_regex_steps |
100,000,000 steps | The work one PCRE subsignature (lookaround or back reference) or one YARA regexp pattern may do on an object; a search that reaches it stops, and the scan is LIMITS-EXCEEDED unless something is found |
--max-matcher-steps |
ScanOptions::max_matcher_steps |
2,000,000 steps per MiB, an object counting as at least 256 MiB | The verification of body signatures with wildcards and gaps in one object, and a 32nd of it for one group of signatures sharing an anchor; past either the search stops, and the scan is LIMITS-EXCEEDED unless something is found |
--min-scan-bytes |
ScanOptions::min_scan_bytes |
6 bytes | Every check on an object smaller than this, which then counts as clean; 0 scans every object |
--max-pe-emulation-steps |
Limits::max_pe_emulation_steps |
1,000,000,000 | Emulator instructions across all packed executables in one file |
--max-unpack-depth |
Limits::max_recursion |
16 | Nesting depth, containers inside containers |
--max-members |
Limits::max_members |
100000 | Member-count blowup; also MFT records, ISO and UDF directories and partition table entries |
--max-extracted-bytes (lowered by --max-process-bytes) |
Limits::max_extracted_bytes |
1 GiB (400M under --clamav-compat) |
What formats that decode a member into memory themselves have produced so far in one scan; never released. A member handed over as a stream is not counted (ZIP, 7z, TAR, CAB and the stream codecs): the scan holds it up to --max-object-bytes and reads a larger one in place or from a spill file, within --max-matcher-bytes |
--max-bytecode-memory-bytes (lowered by --max-process-bytes) |
Limits::max_bytecode_memory_bytes |
256 MiB | What one run of a bytecode signature holds: its mallocs, its call frames and the globals it reads; past it the run stops as incomplete |
--object-cache-bytes (lowered by --max-process-bytes) |
ScanOptions::object_cache_bytes |
32 MiB | Memory held by the block cache of each object read in place; not a limit on what is scanned, only on how often the source is read again |
--object-cache-block-bytes |
ScanOptions::object_cache_block_bytes |
1 MiB | The unit of that cache, and of a request that does not continue the previous one over HTTP |
--http-request-bytes (lowered by --max-process-bytes) |
ScanOptions::http_request_bytes |
8 MiB | The most one HTTP range request fetches, and holds while it is read |
--http-timeout-secs |
ScanOptions::http_timeout_secs |
120 s | The most one HTTP request takes, its body included |
--http-max-redirects |
ScanOptions::http_max_redirects |
10 | Redirects followed to reach an HTTP object |
--max-compression-ratio |
Limits::max_compression_ratio |
1000 | A member that decodes to more than this many times its size in its container, once it is past --max-object-bytes; it is left out and the other members are still scanned |
--max-carved-executables |
Limits::max_carved_executables |
16 of each kind | PE, ELF or Mach-O images carved from one object |
--max-carved-archives |
Limits::max_carved_archives |
32 | Archives carved from one object |
--max-base64-payloads |
Limits::max_base64_payloads |
8 | Executables or archives decoded from the base64 runs of one text |
--max-base64-runs |
Limits::max_base64_runs |
64 | Base64 runs of one text that start like an executable or an archive and are decoded to see |
--max-page-assets |
Limits::max_page_assets |
16 | Base64 assets (data: URIs, inline images) decoded from one page of HTML or flat-XML Office |
Each bound has one spelling; clamscan’s names (--max-filesize,
--max-scansize, --max-files) are refused with an error naming the exav flag.
See the flag matrix.
--max-extracted-bytes is the total a scan may decode whole. It counts the
members that a format decodes into memory itself (OLE streams, PDF streams, RTF
objects, installers, decrypted members and the like), added up over the scan; a
member handed over as a stream is not in it: the scan holds one up to
--max-object-bytes and reads a larger one in place or from a spill file, so a
ZIP, 7z, TAR or CAB that unpacks to several gigabytes is scanned, within
--max-matcher-bytes. It is 1 GiB (400M under
--clamav-compat), off or 0 removes it, and --max-process-bytes lowers
it, together with --max-object-bytes and --max-bytecode-memory-bytes, to what fits
the memory a scan gets (see
the kernel backstops): beside an object held whole, an
image decoded from it and its grey copy can take as much again twice, so one
object is kept to a quarter of that memory, and the total to what leaves room
for those plus a tenth. Matching makes no other copy of an object but a
lowercase one of at most 16 MiB. The
default 2 G changes neither the default limits nor --clamav-compat’s.
--clamav-compat sets --max-input-bytes to 100M, --max-unpack-depth to 17
and --max-members to 10000, and holds 400M per file in total: ClamAV’s scan
size. The largest object held whole stays at --max-object-bytes.
0 and off
Section titled “0 and off”- On a limit (every
--max-flag except--max-unpack-depth, which includes--max-jobs-per-worker, plus?request-secs=and?max-requests=on a listener’s address),0andoffboth mean no limit. An explicit0wins over the--clamav-compatdefault.--startup-wait-secs 0andoffboth mean no wait. - Where no limit would be unsafe, there is no
off:--max-unpack-depth(each level costs stack),?idle-secs=and?max-header-bytes=on a listener’s address (a client could hold a connection forever).0is refused too, but for--max-unpack-depth, where it opens no container. ?session-secs=and?reply-secs=on a listener’s address are off when the key is absent, and refuse0andoff: leaving the key out already says no limit, and a0that elsewhere means none would here read as no time at all.- On a period (
--update-interval-secs,--metrics-secs,--slow-scan-secs),offturns it off and0is refused, because a zero-second period reads as “always”. - Where
0is a value in its own right,offsays something else:--spill-threshold-bytes 0spills every stream at once and has nooff(--spill-dir offkeeps streams in RAM); on an ICAP address,?preview-bytes=0previews headers only andoffleaves the header out, and?options-ttl-secs=0expires at once andoffnever does.--min-scan-bytes 0scans every object and has nooff. - A threshold of findings (
--dlp-credit-cards,--dlp-ssns) refuses0, which would alert on every file; leave the flag out instead. --workersrefuses0; the in-process model is--workers threads.
Notes:
max_buffer_bytesbounds one buffer, not their sum. A container, its member and that member’s member can each be mid-scan at once. The bound on total live memory ismax_extracted_bytes.- A member a format decodes whole that is past
--max-object-bytesis left out, what was decoded of it counts toward--max-extracted-bytes, and the other members of its container are still scanned; the container is thenLIMITS-EXCEEDEDunless something is found. A member its container says is larger than what is left of--max-extracted-bytesis left out before it is decoded, unless the file ends inside it, and the walk goes on; one that decodes past what is left ends the walk of its container there. max_scanned_bytesis a CPU bound. It counts bytes fed to the matcher, not bytes held in memory. Raising it costs only scan time. The bytes hashed for a PE’s section hashes and read for their entropy count toward it too.- What the YARA modules copy counts toward
--max-object-bytes: the names an executable’s imports, exports, sections, symbols and .NET tables refer to, as they are copied for thepe,elfanddotnetmodules and the import hash. max_compression_ratiois the weak one. The input size it divides by is a header field the attacker wrote, so it is a cheap early filter; the byte budgets are what hold. It is asked only of a member whose output passes--max-object-bytes: below that a member is held in memory and the memory limits bound it, and with--max-object-bytes offthere is no output to pass it. A member over the ratio is left out, what was decoded of it counts toward--max-matcher-bytes, and the other members of its container are still scanned; the container is thenLIMITS-EXCEEDEDunless something is found.
One more bound is charged against the rules rather than the file: each buffer
gets 20 million YARA condition-evaluation steps, shared by every rule in the set.
A YARA range loop takes its size from the rule text, so
for any i in (0..200000000) would otherwise stall every scan. A YARA string also
keeps at most one million matches per buffer; one a rule uses at one offset only
($a at 0) is looked for there alone. A scan whose rules run out of steps,
or whose strings reach that count, is reported LIMITS-EXCEEDED unless a rule
matched; real feeds use a few million steps for a whole scan.
Streams: the spill budgets
Section titled “Streams: the spill budgets”A stream (INSTREAM, stdin, an ICAP body), and a member that decodes past
--max-object-bytes, is held in RAM up to a threshold and then in a temporary
file. Reaching one of these has what was held scanned, and is LIMITS-EXCEEDED
unless that finds something.
| Flag | Default | Bounds |
|---|---|---|
--spill-threshold-bytes |
16 MiB | RAM held per object before it spills; with --spill-dir off, the most held at all |
--max-spill-bytes |
2 GiB | Temporary-file space for one object |
--max-total-spill-bytes |
8 GiB | Temporary-file space for every in-flight object in one process |
See Buffering a stream for how they
nest and what --spill-dir off changes.
QR codes
Section titled “QR codes”With --qr (feature qr), the reading of the QR codes in one image is
bounded. Past any bound the scan is LIMITS-EXCEEDED, unless something is
found. off or 0 removes the bound.
| Flag | Default | Bounds |
|---|---|---|
--max-qr-pixels |
50000000 | Pixels an image may have to be read |
--max-qr-millis |
5000 | Milliseconds the reading of one image may take; the reader is stopped wherever it is |
--max-qr-codes |
64 | QR codes read in one image |
--max-qr-finders |
1000 | Finder patterns found in one image |
--max-qr-grids |
256 | Groups of three finder patterns tried as a QR code in one image |
The kernel backstops
Section titled “The kernel backstops”Unix only. They catch what the in-core budgets cannot see: an allocation inside a third-party decoder, or a loop that produces no output.
| Flag | Bounds | Default | Where it applies |
|---|---|---|---|
--max-scan-secs SECS |
Wall clock, and CPU time in the pool | 120 in the pool, unset otherwise | Per job in the clamd worker pool; the whole run in a one-shot scan, which the limit ends where it is, the files after it unscanned, with the exit status of what was found by then (1 for a detection, 2 for an error) and otherwise the one --partial-as gives a LIMITS-EXCEEDED (3). Refused on any other listener (--workers threads, ICAP alone). |
--max-process-bytes SIZE |
Address space (RLIMIT_AS) |
2G in the pool, unset otherwise | Per clamd worker in the pool; the whole process in a one-shot scan or any other listener. |
ICAP scans get no --max-scan-secs in any mode. Under the pool the ICAP
listener runs in a child of its own with no RLIMIT_AS either; the in-core
budgets, fitted to --max-process-bytes, are what bound its scans.
Setting --max-process-bytes also keeps what a scan holds inside it:
--max-object-bytes is lowered to a quarter of it, and the 1 GiB extraction
total to what leaves room for an image decoded from the largest object and its
grey copy (twice its size) plus a tenth. --object-cache-bytes and
--http-request-bytes are each lowered to an eighth of it. The in-core cap
then fires first and reports a limit instead of the kernel killing the scan. In the pool, the per-worker figure is
also lowered to what the host can back: RAM, less a third for the rest of the
system, less the shared database, divided by --workers. A daemon job stopped
by --max-scan-secs is answered LIMITS-EXCEEDED before its worker exits.
For a worked example on one machine, see sizing a server.
What the layers cannot reach
Section titled “What the layers cannot reach”Two failure modes escape every in-process bound:
- An allocation large enough to abort. Rust aborts rather than unwinding, so the per-file panic boundary cannot catch it.
- Stack exhaustion inside a single parser.
max_recursioncounts containers, not recursive descent within one file’s grammar.
Only the kernel layer reaches these: on by default in the worker pool, opt-in elsewhere.
The clamd worker pool contains both: RLIMIT_AS bounds each worker, and a
worker that dies is replaced, so one hostile file costs one job. The pool’s ICAP
child has no such cap: if it dies it is replaced too, but every ICAP connection
it held goes with it. A one-shot run applies the same rlimits when
--max-process-bytes / --max-scan-secs are set, but there is no second
process to fall back on, so the run ends. A
library embedding gets neither unless the host process
sets the rlimits itself.
An in-process allocation counter would not help: refusing an allocation is only
an error the caller can handle where the code asked fallibly (try_reserve), and
almost none of exav’s decoder dependencies do; elsewhere a refusal aborts just as
exhaustion would. Address space is the layer that can say no.
Which one do I change?
Section titled “Which one do I change?”The verdict reason names the budget that stopped the scan. Read it first: the flags bound different quantities, and raising the wrong one changes nothing.
- A large archive of ordinary files:
--max-members. - The total a scan decodes whole:
--max-extracted-bytes. If--max-process-byteslowered it (exav says so at startup, with the figures), raise that first (in the pool, only as far as the host’s RAM allows); past that point raising this one changes nothing. - A bytecode signature that stops as incomplete:
--max-bytecode-memory-bytes. - One large file, or one large member of an archive:
--max-object-bytes(and--max-input-bytesif you set one). Under--max-process-bytesit is also capped at a quarter of that. - A member streamed past the matcher budget:
--max-matcher-bytes. - A scan of a large file or an
http(s)://object that works but is slow: not a limit, so no verdict names it. The object is read from its source several times over, and a request or read per block; see--object-cache-block-bytes,--object-cache-bytesand--http-request-bytes, and the block cache for the figures. - Deeply nested archives:
--max-unpack-depth. - Many packed executables in one file:
--max-pe-emulation-steps. - A stream past a spill budget:
--max-spill-bytes,--max-total-spill-bytes, or--spill-threshold-bytesunder--spill-dir off. - A scan that never returns:
--max-scan-secsin the clamd pool or a one-shot run, and consider whether you want the file scanned at all. An ICAP scan has no time bound; it is bounded by work (--max-matcher-bytes,--max-pe-emulation-steps,--max-unpack-depth,--max-members).
Raising a limit trades resources for reach. The defaults keep a scan of hostile input bounded on a modest host; a build server scanning its own artifacts can afford to be more generous than a mail gateway.