Skip to content

engine: cap header and footer sections at 64 KiB when fields expand - #3284

Merged
dylanmtaylor merged 2 commits into
mainfrom
fix/sec-header-footer-expansion-cap
Nov 4, 2026
Merged

dylanmtaylor merged 2 commits into
mainfrom
fix/sec-header-footer-expansion-cap

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

expand_header_footer (crates/engine/src/cmd/print/header_footer.rs) reads at most 10,000 characters of the header/footer code, but every &A (sheet name), &F (file name), &Z (path), &D, &T, &P, &N appended its whole value again. Sheet names from JSON workbooks are not length-checked, so 5,000 &A codes and a long name could allocate gigabytes before anything was drawn.

What changed

Field values are appended through push_field, which leaves a value out if it would take the section past MAX_SECTION_BYTES (64 KiB). Literal characters were already bounded by the 10,000-character read.

Blast radius

Print, PDF export and Page Layout headers/footers. Real headers are far below 64 KiB and are unchanged.

Checks run

  • cargo test -p gridcraft-engine (full suite; header/footer test extended with a 1 MiB sheet name × 5,000 &A, and 1,000 bytes × 5,000 &A stopping at 65,000 bytes (65 whole names))
  • cargo clippy -p gridcraft-engine --all-targets -- -D warnings
  • cargo fmt --check

Checks not run

  • workspace tests, wasm build

Summary by CodeRabbit

  • Bug Fixes
    • Header and footer fields now have a 64 KiB limit per section. A field value is included only when it fits in full; values that exceed the available space are omitted rather than partially displayed. This applies to page numbers, page counts, dates, times, sheet names, file names, and paths.
    • Added checks for oversized and near-limit field values to confirm the expected display behavior.

The 10,000-character header spec was bounded, but each &A, &F or &Z
added the whole sheet name or path again, and a JSON workbook's sheet
name has no length limit. A field that would take a section past
64 KiB is now left out.
@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 8024a21 and d58afe6.

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

Header and footer field expansion now limits appended values to 64 KiB per section. It omits a field value when the complete value does not fit. Tests cover oversized and fitting repeated sheet-name values.

Changes: Header and footer expansion

Layer / File(s) Summary
Bound field expansion and test its limits
crates/engine/src/cmd/print/header_footer.rs, crates/engine/src/cmd/print/tests.rs
A bounded append helper limits section output to 64 KiB. Page numbers, page counts, date, time, sheet, file, and path use the helper. Tests cover repeated sheet-name values that exceed and fit within the limit.

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

Change: Bug fix

Suggested reviewers: aiongg

Merge Risk: Minimal · previous review 8024a

The reviewed change has no established merge-blocking risk in the supplied scope.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: limiting expanded header and footer sections to 64 KiB.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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 100.00% which is sufficient. 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 2 files.

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 df137b8 and 8024a21.

Files selected for processing: 2
  • crates/engine/src/cmd/print/header_footer.rs
  • crates/engine/src/cmd/print/tests.rs

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

@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 24 minutes and 51 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 25 minutes and 32 seconds before sending another message.

@dylanmtaylor
dylanmtaylor merged commit bebe7de into main Nov 4, 2026
8 of 9 checks passed
@dylanmtaylor
dylanmtaylor deleted the fix/sec-header-footer-expansion-cap branch November 4, 2026 03:55
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