#3032·LiteDB

Fuzz harness: compact bulk replay input and enforce a true global artifact budget

Author: JKamskerCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugv6severity: mediumpriority: P2

Summary

The 2026-09-28 nightly fuzz run produced #3028, #3029 and #3030, but these are fuzz-harness artifact-budget failures, not LiteDB engine correctness findings.

The affected targets are:

  • #3028 — storage: ARTIFACT_BUDGET_STORAGE
  • #3029 — storage-failure: ARTIFACT_BUDGET_STORAGE_FAILURE
  • #3030 — page: ARTIFACT_BUDGET_PAGE

Run: https://github.com/litedb-org/LiteDB/actions/runs/36371270813
Head: b08190e2f5d38f291f3f860b793658c46a5d17d1

The run reached roughly 1.06 GiB in the correctness shard and 1.4 GiB in the persistence shard before later targets were budget-stopped. The uploaded artifacts were about 1.04 GiB and 2.34 GiB respectively.

Root cause

1. Bulk random data is encoded very inefficiently in input.bin

FuzzInputRandom.NextBytes() currently generates every output byte via NextUInt32():

csharp
public override void NextBytes(byte[] buffer)
{
    for (var i = 0; i < buffer.Length; i++)
        buffer[i] = (byte)NextUInt32();
}

Each NextUInt32() persists a full 4-byte word to input.bin. Therefore generating N random payload bytes records approximately 4N replay bytes.

This is especially expensive for FileStorage fuzzing:

  • storage-failure generates roughly two 255 KiB chunks per step.
  • storage frequently generates payloads up to roughly two 255 KiB chunks.
  • page is sufficiently fast that many smaller random payloads accumulate to the same problem during a two-minute epoch.

Duration-bound fuzzing has no count limit, so these targets can produce hundreds of MiB of replay input within one epoch.

2. The configured 512 MiB budget is not a true shared/root budget

BudgetReached() checks the shared artifact root before an epoch starts.

While an epoch runs, however, RunCoreAsync() checks only:

csharp
FuzzArtifacts.DirectorySize(directory)

where directory is that individual run directory.

With multiple workers/process slots running concurrently, each active epoch can independently grow toward the full 512 MiB limit. The shared root can therefore exceed the configured budget by a large factor before the workers are stopped.

3. Budget failures retain the largest offending file

WriteArtifactBudgetFailureAsync() removes database files, coverage and dumps, but retains input.bin.

For these failures, input.bin is the main source of the artifact explosion. The budget mechanism therefore kills the run but still uploads the bulk of the data that triggered the budget.

Impact

  • Nightly fuzz coverage is cut short: many later targets are never executed.
  • CI uploads multi-gigabyte artifacts for harness failures.
  • Automated issue filing creates misleading engine-looking findings for what is really an infrastructure/resource problem.
  • Parallel workers can exceed the intended root budget substantially.

There is currently no evidence from #3028-#3030 of a BasePage, FileStorage, WAL, recovery or durability defect.

Proposed fix

Compact bulk replay data

Avoid recording one 32-bit RNG value for every generated byte.

A suitable design is to encode a bulk-byte operation as a compact deterministic descriptor, for example:

operation = FillBytes
length = N
seed/state = X

and use a stable/versioned byte generator to reproduce the payload.

Requirements:

  • deterministic replay remains exact;
  • old recorded input.bin files remain replayable, or the encoding is explicitly versioned with a compatibility reader;
  • minimization/input-offset semantics remain valid;
  • large NextBytes() calls grow the replay artifact approximately with call count/metadata, not payload size.

Enforce a true shared artifact budget

The root budget should account for active workers, not only completed epochs.

Possible approaches:

  • reserve artifact capacity before starting/continuing an epoch;
  • maintain a shared atomic/root usage counter plus per-run reservation;
  • or otherwise stop/compact active epochs before aggregate root usage materially exceeds the configured cap.

The exact mechanism is less important than making --max-artifact-mb 512 mean approximately 512 MiB for the whole fuzz invocation, not 512 MiB per concurrently-running epoch.

Budget-failure retention

For ARTIFACT_BUDGET_*:

  • retain enough metadata for deterministic seed/compact replay;
  • do not retain a hundreds-of-MiB input.bin when the compact/seed replay can reproduce it;
  • keep ordinary real fuzz failures conservative: failure evidence must not be discarded merely to save artifact space.

Tests

Add regression coverage proving:

  1. generating a large byte buffer does not create ~4x payload size in input.bin;
  2. replay reproduces the exact bytes;
  3. legacy replay remains supported if the format changes;
  4. two or more concurrent artificial artifact producers cannot each consume the whole root budget;
  5. artifact-budget termination leaves a small replayable artifact;
  6. ordinary assertion/crash/hang failures still retain their required evidence.

Acceptance criteria

  • Bulk NextBytes() replay encoding is compact and deterministic.
  • Existing replay compatibility is preserved or explicitly versioned/migrated.
  • The configured artifact limit applies to the aggregate fuzz root across concurrent workers.
  • ARTIFACT_BUDGET_* artifacts do not retain the bulk data that caused the overflow when compact replay is sufficient.
  • Nightly storage, storage-failure, and page can run their allocated epochs without artifact-budget findings under normal workloads.
  • #3028, #3029 and #3030 remain classified as harness manifestations, not engine regressions.

Related: #2947, #2994.