You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calc: cap the text one & over arrays may build in all - #3189
& 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.
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.
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.
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: 3 · 1 · 1
Failed checks: 1 warning · 1 inconclusive
Check name
Status
Explanation
Resolution
Docstring Coverage
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
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 checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
&over arrays (binary_valuesincrates/calc/src/eval/array.rs) builds one string per output cell. Each string is capped on its own and the cell count is capped atMAX_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 throughconcat_arrays, which counts the bytes it has built. PastMAX_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.&and every other operator are unchanged.#NUM!at 5 KB, with either operand as the array.Blast radius
gridcraft-calconly: results of&over arrays larger than 512 MiB of text, which could not be held before.Checks run
cargo test -p gridcraft-calc --libcargo clippy -p gridcraft-calc --all-targets -- -D warningscargo fmt -p gridcraft-calc --checkChecks not run
cargo xtask ci(engine tests, fuzzers, wasm): left to CI.Addresses CodeRabbit security findings (CWE-400).
Summary by CodeRabbit
#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.