Repository navigation
Reject row/column insert counts past the worksheet and clamp delete counts instead of overflowing (#531) - #627
Merged
Conversation
…ounts instead of overflowing (storytold#531)
MarekSpodBiedry
marked this pull request as ready for review
October 12, 2026 06:54
…t shadow it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
h-a-n-a-s-h-i
pushed a commit
that referenced
this pull request
Oct 13, 2026
Member
|
Merged — thank you @MarekSpodBiedry for the contribution! I pushed a small fix to the branch before merging: the test helper |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #531.
home.insertRows,home.insertColumns,home.deleteRowsandhome.deleteColumnsreadcountthroughu32_param, which accepts anyu32. Nothing boundedat + countbefore the unchecked additions ininsert_lines(the "Format Same As Above" loopat..at + count) anddelete_lines(the block endat + count - 1and the shift originat + count). With overflow checks on, those panicked andSession::executereturnedEngineError::Internal. In release builds they wrapped.Insert:
insert_linesnow checksat.checked_add(count)againstMAX_ROWS/MAX_COLSbefore doing anything else and returnsBadParamsfor the command when the new lines would run past the end of the worksheet. This is the same checksheet.moveColumnsalready uses (checked_add+is_none_or(|end| end > MAX_COLS)→bad("sheet.moveColumns", …)). The existing "cannot shift nonblank cells off of the worksheet" guard is unchanged, and it still catches data being pushed off the sheet.Delete:
delete_linesclampscountto the lines left fromatto the end of the worksheet. The block end was already clamped with.min(MAX_ROWS - 1), so the existing intent was already "delete up to the end of the sheet". Clampingcountfirst means the shift origin andEdit::Deleteget the same, representable count.home.insertCells/home.deleteCellswithshift: row|columngo through the same two functions, so they are covered too.Tests (
crates/engine/tests/line_count_overflow.rs), all on both axes:count: u32::MAXreturnsBadParamsBadParams. Without the fix this hits the overflowing loop.count: u32::MAXdoesn't returnInternal