← Back to Pull requests

fix(engine): bound decoded string columns before they expand #273

Closed
unknown closed this pull request without merging on Nov 21, 2026 20:42 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 01:26 UTC
Author

What and why

Follow-up to #242 (P52). QUERY_MAX_DECODED_MIB was 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.

  • Each decoded batch's Arrow memory now counts against the limit as registration decodes.

  • Top-level string and binary columns decode as view arrays (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.
  • Dictionary arrays would not do. In parquet 59.3.2, byte_array_dictionary.rs calls spill_values and expands the keys read so far whenever a batch crosses into another row group, or from dictionary pages to plain ones.

  • Fixed-width columns (including dictionary-encoded 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.

  • The reader is capped at the rows the footer's row groups declare, and a batch larger than the one just checked is refused as malformed, so the pre-batch check cannot be outrun by a footer that understates its rows.

  • A batch that would need more than 32-bit offsets is refused as malformed before the cast, which would otherwise panic. This applies to plain values and to a dictionary's distinct values.

  • The table schema is unchanged; columns are cast back to the file's own types.
  • ADR 0013, docs/ARCHITECTURE.md, QueryLimits docs, .env.example and 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):

  • A DELTA_BYTE_ARRAY page rebuilds each value from its predecessor's prefix, so it can copy up to its own size once per row of a batch.

  • List columns, and strings or binary inside a struct, are counted only after they expand.

  • A page decompresses whole, to the size its own header states.

  • Columns declared as view types, or as dictionaries of non-byte types, share buffers across batches and are counted once per batch, so they can be refused below the limit.
  • 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 Dictionary hint 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 with Parquet(Batch).

  • string_columns_keep_their_type: nullable Utf8, LargeBinary and a declared Dictionary(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 KiB FIXED_LEN_BYTE_ARRAY passes the footer check and is refused with DecodedBytes. 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 declared Dictionary(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 with Parquet(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.

  • Local results: cargo fmt --check, all three clippy passes (default, --all-features, production --bins) and cargo test --workspace (679 passed).
  • Checklist

  • scripts/check.sh passes locally. The backend steps pass. It stops at the wasm step because the local wasm-bindgen CLI 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.

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs: no new decision, only the existing decoded_bytes limit refusal.

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made (ADR 0013 updated)
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: abendrothj Review duration: 2596m
    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
    0.52
    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%
    56%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #273"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 22.5% · Safe to merge
    22.5%