Security: duplicate-identity grant fold is linear; manifest sync_runs decode is bounded #1165
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.71) × (1 − Review Confidence (0.54)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 513 lines diff across 6 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.373
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.071
Real PR Conversation Timeline
1 comments
"Review active on #1165"
general
weight: 0.35
pquerna
Summary
C1Z-SEC-008, two findings on
.c1zimport:1. Duplicate-identity grant fold was quadratic.
mergeDuplicateGrantValuesfolds a group of grant rows that share one structural identity. It runs in the id-index migration and in the bulk import'sresolveDuplicateGrants. It merged pairwise, rebuilding the annotation union (new seen-map and full re-sort) and re-cloning the sources map at every step. A v1 c1z can hold any number of rows with distinct external ids that fold to one identity, so one group of 8192 rows took 13.5s inside a single uninterruptible call.2. The manifest header's
sync_runsdecode had no bound of its own. Only the 16 MiB manifest cap limited it. Decoding allocates a message per run and a map entry per stats key, so a header read could cost hundreds of MiB of heap. Header reads happen on every open, through engine dispatch.Changes
Duplicate-identity fold: one pass, same bytes
grantRecordFoldapplies the existing per-field rules one row at a time: identity winner, needs_expansion OR, annotation union, sources merge by key, expansion id union with Shallow AND. Each row costs time proportional to its own size, so a group is linear in its total size (8192 rows: 0.07s).recordIdentityInfoWinsandminNonEmptyStringremain the shared rules.Manifest
sync_runs: bounded decode, never rejectedmaxManifestSyncRunsBytes(1 MiB). Past that it drops the whole projection.-
selectSourceSyncFromManifestfalls back to unpacking the payload.-
c1zSyncIDBestEffortis used only for logs.StartNewSyncwipes the keyspace, and the retention options apply only to SQLite. So a written projection is one run of roughly 0.1–6 KB (about 2 KB for a typical connector with stats), and the 1 MiB budget is only reached by crafted headers. Reading such a file without its projection is safer than refusing to open it.SyncStatsRecordmaps can be as large as millions of runs.Tests
TestMergeDuplicateGrantValuesMatchesPairwiseFoldis a differential test. It runs 2000 seeded random groups of 2–5 rows covering single-contributor fields, duplicate annotations, colliding sources, empty expansion ids and discovered_at ties. Each group's merged bytes must equal those of the previous pairwise fold, which lives in the test file as the reference. Canonicalizing a single contributor (the earlier revision of this PR) fails it at group 1.TestSecurity_MergeDuplicateGrantValuesLargeGroupfolds an 8192-row group with a distinct annotation and source per row, under a 5s bound, and checks that reversing the input order gives the same bytes. The pairwise fold takes 16.3s on the same input.TestManifestSyncRunsProjectionBudgetwrites envelopes withWriteEnvelopeand reads them back withReadManifestHeader:- 2 runs, and exactly as many runs as fit the budget, read back whole;
- one run more reads back with no error and no projection, other header fields intact;
- with the bound removed, the over-budget case decodes every run and fails.
TestMergeDuplicateGrantValuesFoldOrderIndependentand the migration and bulk-import suites.golangci-lint run ./...: 0 issues.go test -short -tags=baton_lambda_support ./...: passes.go test -racepasses onpkg/dotc1z/engine/pebbleandpkg/dotc1z/format/v3.