Skip to content

cold-store-reaper(worker): zstd decompression is unbounded — a small frame expands without limit before the sha256 check, and the manifest's expected plaintext size is selected but never used #6590

Closed

Description

@dezren39

cold-store-reaper(worker): zstd decompression is unbounded — a small frame expands without limit before the sha256 check, and the manifest's expected plaintext size is selected but never used

Evidence (verified this run, laptop @ 9123103 == origin/main)

The rehydrator Worker (pkgs/cold-store-reaper/worker/) verifies an object's sha256 before serving it, but the verification happens after the frame has been decompressed whole, with no size bound at any point:

  • src/decoder.js:12 — decompressFrame(frameBytes) is exactly return decompress(frameBytes) (fzstd): the whole expanded output is allocated in memory, whatever size the frame declares/produces.
  • src/index.js:196 — BundleFlight.rehydrate calls decompressFrame(frame) on the Drive-pulled frame; the sha256 comparison (src/index.js:200-203) runs only on the fully expanded plain.
  • src/index.js:169 — rehydrate destructures only { drive_file_id, offset, frame_length, sha256, bundle_id } from the job. The entry-point SQL (src/index.js:229) already selects o.size AS size — the object's expected plaintext size — and the row is posted whole to the Durable Object, so the one number that could bound the expansion is in the job and is never read.

Probe (laptop, ~/git/fleet/probe-coldstore-bomb/, fzstd from the worker's own package.json/package-lock.json, zstd -19 CLI frame):

  • Frame of 64 MiB of zero bytes: 2,077 compressed bytes → 67,108,864 decompressed bytes, RSS +70.1 MiB, via the same decompress() call decompressFrame makes. The expansion ratio scales with the frame, not with frame_length: a few-KiB frame can declare/expand past the Worker's 128 MB memory limit, so a corrupt or hostile bundle member kills the Worker/DO with an out-of-memory crash instead of producing the designed clean 502 ("refusing to return unverified bytes").
  • Control intent already in the tree: the Range-ignored download path was bounded for exactly this reason (perf(cold-store-reaper): bound memory when Drive ignores Range requests #6182 — readStreamedFrame, src/index.js, "peak memory tracks frame_length rather than the bundle size"). Decompression is the remaining stage where peak memory tracks neither the frame size nor the expected object size.

Why it matters

The Worker's contract is fail-closed with a 502 on any Drive, decompression, or hash failure. An unbounded decompress breaks that contract in the worst direction: instead of a 502, the isolate dies — for the single-flight Durable Object, taking down every joined concurrent fetch for that bundle with it. It also makes the service fragile for legitimate restorations: any object whose plaintext is large relative to isolate memory cannot be served (or refused cleanly) because the known expected size is ignored. The data needed to fix it is already flowing through the job.

Acceptance criteria

  • Decompression in the rehydration path is bounded by the expected plaintext size: a frame that expands past the manifest's o.size for the object aborts with the existing 502 HttpError shape, without materialising the full expansion (e.g. streaming/chunked decompression with a running total, or an up-front refusal when the frame's declared content size exceeds the expected size).
  • A frame whose expansion is exactly the expected size and whose sha256 matches is served exactly as today (control case unchanged); a short/legitimate frame is unaffected.
  • rehydrate actually uses the job's size field (already selected at src/index.js:229); a job with a missing/non-numeric size fails closed rather than falling back to unbounded decompression.
  • A regression test in the worker test suite (pkgs/cold-store-reaper/worker/test/, run by npm test) crafts a high-expansion frame (small compressed size, claimed/actual expansion far beyond the expected size) and asserts the bounded refusal, alongside the existing local-proof and Range-ignored tests passing.

Activity

  1. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/cold-store-reaperPackage/app: cold-store-reaper (pkgs/ or apps/ in this repo)
    on Nov 6, 2026
  3. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (Lane B), agent slug new-issue-creator-code-b
    • Session / ID: cron job new-issue-creator-code-b, run 2026-11-06 11:50 CST
    • Found via: filed this run
    • Task: Triage the unbounded zstd decompression in the cold-store rehydrator Worker — decompressFrame expands a frame whole before the sha256 check, and rehydrate ignores the job's expected plaintext size (o.size, already selected) that could bound it
    • Expectation: effort/s — done when decompression is bounded by the expected size with a clean 502 on over-expansion, pinned by a high-expansion-frame regression test in the worker suite
    • Links: probe ~/git/fleet/probe-coldstore-bomb on the laptop (worker's own fzstd; 2,077-byte frame -> 67,108,864 bytes, RSS +70.1 MiB)
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Picked up by repo-worker-code-p (lane code-p, repo-queue worker shift, FALLBACK MODE — queue backend down: fleet queue health/claim failing HTTP 503 PGRST002, code#6619). Working issue #6590 under the worker runbook §0a fallback protocol.

  5. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 7, 2026
  6. 15 remaining items

  7. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  8. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-i: picked up: rehydrate/decoder read on current main — size is selected in SQL and posted in the job but never read; decompressFrame is a bare fzstd decompress(); next: worktree, inspect fzstd streaming API, implement bounded decompression

  9. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-i: pr_opened: PR for issue #6590 opened (branch queue/fallback-6590-bounded-decompress, commit 9c5cf19); npm test fully green on laptop (local proof + range-ignored + 14 bounded-decompress checks), dist rebuilt; next: PR checks + Codex, then merge under standing criteria

  10. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-i: Codex P1 x2 on PR #6726 — dispositioning by fixing both: (1) frame-header pre-check bounding the header-driven window allocation + declared content size before streaming; (2) property-based decoder tests with named oracles incl. hand-crafted large-window frames. Not merging past undispositioned findings.

  11. added a commit that references this issue on Nov 7, 2026
  12. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  13. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Released by repo-worker-code-i (outcome: done). Outcome: fixed_merged. PR #6726 merged (merge commit 7e903f6); issue #6590 auto-closed. Rehydration decompression is bounded by the job size (validated, fail-closed 502 when missing/non-numeric); decoder streams with a running output bound, refuses oversized declared content size / declared window up front (max(limit, 8 MiB) window cap), and rejects concatenated frames. Three Codex P1 rounds all fixed in-PR, replied, and resolved; round 3 had no new findings. npm test fully green on laptop; dist rebuilt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/cold-store-reaperPackage/app: cold-store-reaper (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus/triagedTriaged and routed (see agent note)status:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions