Security: grant source-fact sort is linearithmic on hostile order #1164
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.65) × (1 − Review Confidence (0.58)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.65 · 335 lines diff across 4 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.348
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.065
Real PR Conversation Timeline
1 comments
"Review active on #1164"
general
weight: 0.35
pquerna
Summary
C1Z-SEC-007. The grant digest build and repair paths compute every grant row's content hash from its raw stored value:
1.
scanGrantContentFactsRawBytescollects onegrantSourceFactpersourcesmap entry.2.
sortGrantSourceFactssorts and dedupes them.The sort was an insertion sort, and both the list's length and its order come from the stored value. A descending 2^16-entry sources map took 8.9s for one row, with no cancellation check inside the row. A larger map grew quadratically from there. A hostile
.c1zreaches these paths through EndSync's digest build and digest repair on the shared workers.Change
sortGrantSourceFactsnow usesslices.SortStableFunc:Why no cap on the sources count
An earlier revision also rejected values with more than 2^16 sources. I dropped it:
FuzzGrantContentHashRawMatchesDecodedsays the raw scan accepts every valueproto.Unmarshalaccepts and hashes it likegrantContentHashForRecord. A cap would make the raw path reject valid grants thatGrantContentHashhashes fine.Tests
TestSecurity_SortGrantSourceFactsDescendingInputsorts 2^16 descending facts and must finish under 2s. With the insertion sort restored it fails at 8.98s; with this change it takes about 10ms.-
TestGrantDigestSpliceMatchesEncodecompares raw-scan and decoded-record hashes, including unsorted multi-source maps.-
TestGrantContentHashRawMatchesDecodedOnDuplicateWireFieldscovers last-write-wins on duplicate wire keys.- The
FuzzGrantContentHashRawMatchesDecodedseed corpus.golangci-lint run ./...: 0 issues.go test -raceonpkg/dotc1z/engine/pebblepasses.go test -short -tags=baton_lambda_support ./...: everything passes exceptTestC1ZConcurrentClose. It failed once under full-suite load and passed 5 runs in isolation. It is a SQLite concurrent-close test this change does not touch.