Skip to content

fix(run-evidence): bound the summary read and stream artifact hashes - #355

Open
DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/run-evidence-bounded-summary
Open

DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/run-evidence-bounded-summary

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

readHardenRunSummary read whatever path the caller supplied with readFileSync(..., "utf8"), and sha256File read whole artifacts before hashing. The summary lookup is exposed through bla_run_lookup, so an arbitrary large file could be buffered just to fail JSON parsing, and a multi-gigabyte model output was loaded whole for a digest.

The rest of the evidence path already uses bounded reads and chunked hashes (manifest-verify, output-registry, verify-sidecar). This brings the shared helper in line.

What changed

  • readHardenRunSummary now rejects a summary above MAX_HARDEN_SUMMARY_BYTES (8 MiB) and requires a regular file, with an explicit error that names the size and the ceiling.
  • sha256File streams the file through a 1 MiB buffer with openSync, readSync and closeSync, producing the same SHA-256 as the previous whole-file read.
  • tests/run-evidence-bounded.test.ts covers an oversized sparse summary and compares the chunked digest to crypto.createHash over the same bytes.

Compatibility

Digests are identical. Summaries BLA writes are small, so normal lookups are unaffected. A caller that intentionally points bla_run_lookup at a file larger than 8 MiB now gets a clear refusal instead of a parse error or an out-of-memory path.

Verification

  • npx vitest run tests/run-evidence-bounded.test.ts tests/run-evidence.test.ts tests/harden-apply-*.test.ts passes, 22 tests with 1 skipped.
  • npx tsc --noEmit is clean.

A caller-chosen run summary could be any size, and sha256File loaded whole artifacts into memory. Cap the summary at 8 MiB and hash artifacts in 1 MiB chunks; both behaviours are covered by focused tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant