← Back to Pull requests

Security: cap directories created by c1z payload extraction (C1Z-SEC-009) #1166

Closed
unknown closed this pull request without merging on Oct 04, 2026 02:35 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 00:41 UTC
Author

Summary

C1Z-SEC-009. Payload extraction creates the directories its entry names imply:

  • the tar extractor calls MkdirAll(target) for TypeDir entries and MkdirAll(Dir(target)) for TypeReg entries;

  • the indexed extractor calls MkdirAll(Dir(target)) for every entry.
  • A name made of one-byte components creates one directory per component. That is about 127 directories per 512-byte ustar header and about 2000 per PAX long name. The decoded-byte budget, max(10 GiB, 100× file size), charges a header the same whatever its name implies. So a few-MB envelope could create tens of millions of directories and run the worker's filesystem out of inodes long before the budget runs out.

    Change

    Both extractors now create directories through extractDirs. It caps one extraction at maxExtractedDirs (1024) directories and fails with ErrMaxSizeExceeded past that.

  • Counted from names, before touching disk. mkdirAll walks up from the requested directory until it reaches one it already created. It refuses before calling os.MkdirAll if the missing ones would exceed the cap. The number of directories on disk therefore never passes the cap, whatever the path depth.

  • Shared parents count once. The created set holds every ancestor of each directory in it, so a thousand files under x/y/ cost two directories.

  • Honest payloads are nowhere near it. A payload is a Pebble checkpoint, a flat directory written by writeTar/writeIndexedZstd walking dbDir, so it creates no directories or a handful.

  • The walk stays cheap. Each entry does at most one lookup per newly created directory, plus one, so total work stays linear in the payload.
  • No exported API changes. ExtractZstdTar and ExtractEnvelopePayload keep their signatures, so existing callers are protected without changes, including c1's ExtractZstdTar(env.PayloadReader, dir).

    Why not charge directories to the decoded budget

    An earlier revision charged 512 budget bytes per implied directory. That required exporting DecodedBudget, Charge, ExtractZstdTarBudgeted and Envelope.PayloadBudget, plus a c1 follow-up. It still allowed about 21M directories at the 10 GiB default, and it missed the indexed extractor. A directory costs an inode and a directory block regardless of the payload's size, so a fixed count is the right bound.

    Tests

    TestSecurity_ExtractionCapsDirectories, at default settings:

  • tar entry whose name has 1025 directory components: ErrMaxSizeExceeded, no directories created;

  • 1025 shallow tar directory entries: ErrMaxSizeExceeded, exactly 1024 created;

  • 2048 files under shared x/y/: extracts, 2 directories;

  • indexed envelope with 1025 files in distinct directories: ErrMaxSizeExceeded, exactly 1024 created.
  • With the cap removed, every refusal case fails and the shared-parents case still passes. The existing round-trip and cardinality tests pass unchanged.

  • golangci-lint run ./...: 0 issues.

  • go test -short -tags=baton_lambda_support ./...: passes.

  • go test -race ./pkg/dotc1z/format/v3: passes.
  • Not in this PR

    File count is still bounded only by the decoded budget at 512 bytes per entry, which is about 21M empty files at the 10 GiB default. That is a separate decision about how many inodes one extraction may use.

    Diff: 413 lines (+309 / -104) across 5 files Reviewer: pquerna Review duration: 113m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.68) × (1 − Review Confidence (0.54)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.68 · 413 lines diff across 5 files
    0.68
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    54%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.068
    Real PR Conversation Timeline
    1 comments
    "Review active on #1166"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 54.2% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 68.1% (HIGH) · Higher = larger blast radius
    68.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 54.2% · Lower = rushed or shallow review
    54.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.1% · Safe to merge
    31.1%