fix(engine): bound decoded string columns before they expand #273
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #273"
general
weight: 0.35
abendrothj
What and why
Follow-up to #242 (P52).
QUERY_MAX_DECODED_MIBwas checked only against the sizes Parquet footers declare. Those understate dictionary- and run-length-encoded columns, so a few-KiB upload could decode a gigabyte or more inside the enclave.Utf8View/BinaryView). This includes columns the file's embedded Arrow schema declares as dictionaries. Views point into the pages and dictionaries they came from, so nothing is copied per row while decoding.- A plain column's expanded size is measured from its views' lengths and refused (422,
decoded_bytes) before the cast back copies it.- A dictionary column is rebuilt with one key per distinct value. Rows are keyed first by where their value is stored, then by the value, so a stored value is read once. This holds even where the reader lists a dictionary's buffer again under a new index after a plain page. Equal values stored apart (plain pages, another row group's dictionary) share a key, so a narrow declared key type does not overflow. The distinct values are measured against the budget before anything is copied.
byte_array_dictionary.rscallsspill_valuesand expands the keys read so far whenever a batch crosses into another row group, or from dictionary pages to plain ones.FixedSizeBinary, and a declared dictionary's fixed-width values as well as its keys) are checked from their widths and the rows left before each batch decodes, since a dictionary page can expand them to width × 1024 inside the reader.ADR 0013,
docs/ARCHITECTURE.md,QueryLimitsdocs,.env.exampleand CHANGELOG are updated. The rejected alternative "Counting decoded Arrow memory while decoding" is removed, since this now does it.Residuals (documented in ADR 0013 and ARCHITECTURE):
DELTA_BYTE_ARRAYpage rebuilds each value from its predecessor's prefix, so it can copy up to its own size once per row of a batch.How it was tested
a_repeated_value_is_refused_before_it_expands: two files in which one batch would expand past 2 GiB.- One crosses from dictionary pages to plain pages: 1000 rows of a 3 MiB value.
- One crosses a row-group boundary: two groups of 512 rows of a 5 MiB value.
- Both pass the footer check and are refused with
DecodedBytes.- A negative control with the old
Dictionaryhint fails both with the reader's index overflow (Parquet(Batch)).a_declared_dictionary_is_not_expanded: the same files with their Arrow schema embedded register as dictionaries. With the dictionary arm removed from the hint, the test fails at registration withParquet(Batch).string_columns_keep_their_type: nullableUtf8,LargeBinaryand a declaredDictionary(Int8, Utf8)round-trip with exact measured sizes, and a refusal one byte under budget.a_wide_fixed_column_is_refused_before_it_decodes: a Parquet 2.0 file with a dictionary-encoded 64 KiBFIXED_LEN_BYTE_ARRAYpasses the footer check and is refused withDecodedBytes. The post-batch count would also refuse it, after the reader had allocated the batch, so this test does not distinguish the two.equal_long_values_share_a_key: 500 rows of one 24-byte value declaredDictionary(Int8, Utf8), written plain and with one row group per row. Each row has a view of its own, and the column still round-trips and registers. Before the fix both were refused withParquet(Batch).a_value_listed_under_many_views_takes_one_key: one buffer listed four times, as the reader does after plain pages; every row takes one key. It checks the keys only. Nothing measures that the value is read once.the_decode_limit_counts_what_decoding_produces: a dictionary-encoded upload under the footer limit is refused from what it decodes to.cargo fmt --check, all three clippy passes (default,--all-features, production--bins) andcargo test --workspace(679 passed).Checklist
scripts/check.shpasses locally. The backend steps pass. It stops at the wasm step because the localwasm-bindgenCLI is 0.2.128 and Cargo.lock pins 0.2.126, so the wasm and frontend steps are left to CI; neither is touched here.SECURITY_AUDIT_EVENTcovered byaudit_coverage.rs: no new decision, only the existingdecoded_byteslimit refusal.docs/DATA_POLICY.md)CHANGELOG.mdupdated for user-visible changesdocs/adr/if one was made (ADR 0013 updated)