Skip to content

calc: cap the text one & over arrays may build in all - #3189

Merged
dylanmtaylor merged 3 commits into
mainfrom
fix/sec-concat-bytes
Nov 4, 2026
Merged

dylanmtaylor merged 3 commits into
mainfrom
fix/sec-concat-bytes

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

& over arrays (binary_values in crates/calc/src/eval/array.rs) builds one string per output cell. Each string is capped on its own and the cell count is capped at MAX_CELLS, but nothing bounds the total: SEQUENCE(4000,4000)&REPT("x",30000) asks for about 480 GB of text, and a short formula can exhaust the app's memory.

What changed

  • & with an array operand goes through concat_arrays, which counts the bytes it has built. Past MAX_CONCAT_ARRAY_BYTES (512 MiB) it stops building and the result is #NUM!, the error already used for an array result that is too large.
  • Scalar & and every other operator are unchanged.
  • Regression test: a 100-cell broadcast concatenation fits a 20 KB budget and is #NUM! at 5 KB, with either operand as the array.

Blast radius

gridcraft-calc only: results of & over arrays larger than 512 MiB of text, which could not be held before.

Checks run

  • cargo test -p gridcraft-calc --lib
  • cargo clippy -p gridcraft-calc --all-targets -- -D warnings
  • cargo fmt -p gridcraft-calc --check

Checks not run

  • cargo xtask ci (engine tests, fuzzers, wasm): left to CI.

Addresses CodeRabbit security findings (CWE-400).

Summary by CodeRabbit

  • Bug Fixes
    • Array text concatenation now returns #NUM! when the combined result exceeds 512 MiB, preventing oversized results. Scalar concatenation retains its existing per-cell text limit, and other operators are unaffected.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2fa8aee and ff0103c.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Array broadcasting now supports incremental result construction that stops when a callback rejects a cell. Array concatenation tracks generated text bytes and returns #NUM! when the 512 MiB limit is exceeded. Scalar concatenation and other binary operators retain the existing element-wise path.

Changes: Array Operations and Concatenation

Layer / File(s) Summary
Broadcasting and budgeted concatenation
crates/calc/src/eval/array.rs
try_zip2 stops processing when its callback rejects a cell and reports invalid broadcast sizes with #NUM!. Array concatenation tracks generated text bytes and returns #NUM! above the 512 MiB limit. Tests cover early termination, results below and above the limit in either operand order, and the small-result path through binary_values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • storytold/gridcraft#2157: The issue proposes a byte budget for large-array string operations. This change adds a budget for array concatenation, but does not implement the wider per-pass budgets described in the issue.

Suggested reviewers: maxm11

Merge Risk: Minimal · previous review 2fa8a

No merge-blocking risk remains. Large successful array concatenations can retain extra buffer capacity, but the demonstrated impact is bounded.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check Inconclusive The title refers to the array text-size cap, but its wording is unclear and does not clearly describe the main change. Replace the title with a concise, clear sentence such as "calc: cap total text size for array concatenation".
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c233917 and 2fa8aee.

Files selected for processing: 1
  • crates/calc/src/eval/array.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread crates/calc/src/eval/array.rs Resolved
@dylanmtaylor

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@dylanmtaylor have exceeded the limit for the number of chat messages per hour. Please wait 25 minutes and 32 seconds before sending another message.

@dylanmtaylor

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@dylanmtaylor have exceeded the limit for the number of chat messages per hour. Please wait 26 minutes and 13 seconds before sending another message.

@dylanmtaylor

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@dylanmtaylor have exceeded the limit for the number of chat messages per hour. Please wait 2 minutes and 45 seconds before sending another message.

@dylanmtaylor
dylanmtaylor merged commit c0ea297 into main Nov 4, 2026
8 of 9 checks passed
@dylanmtaylor
dylanmtaylor deleted the fix/sec-concat-bytes branch November 4, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant