Security: cap directories created by c1z payload extraction (C1Z-SEC-009) #1166
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
pquerna
Summary
C1Z-SEC-009. Payload extraction creates the directories its entry names imply:
MkdirAll(target)forTypeDirentries andMkdirAll(Dir(target))forTypeRegentries;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 atmaxExtractedDirs(1024) directories and fails withErrMaxSizeExceededpast that.mkdirAllwalks up from the requested directory until it reaches one it already created. It refuses before callingos.MkdirAllif the missing ones would exceed the cap. The number of directories on disk therefore never passes the cap, whatever the path depth.x/y/cost two directories.writeTar/writeIndexedZstdwalkingdbDir, so it creates no directories or a handful.No exported API changes.
ExtractZstdTarandExtractEnvelopePayloadkeep their signatures, so existing callers are protected without changes, including c1'sExtractZstdTar(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,ExtractZstdTarBudgetedandEnvelope.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:ErrMaxSizeExceeded, no directories created;ErrMaxSizeExceeded, exactly 1024 created;x/y/: extracts, 2 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.