Skip to content

xlsx: error on cell references beyond the grid limits - #696

Open
krickert wants to merge 3 commits into
tafia:masterfrom
ai-pipestream:fix/cellref-overflow
Open

xlsx: error on cell references beyond the grid limits#696
krickert wants to merge 3 commits into
tafia:masterfrom
ai-pipestream:fix/cellref-overflow

Conversation

@krickert

@krickert krickert commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #694.

Both accumulators in get_row_and_optional_column were unchecked u32, so a reference like ZZZZZZZ1 or A99999999999 panicked in debug builds and wrapped in release builds, yielding cell positions that appear nowhere in the file.

As requested in review, the fix rejects invalid references instead of guarding the arithmetic: row and column accumulation is checked, and a reference past the grid (row > 1,048,576 or column > 16,384) returns the existing XlsxError::RowNumberOverflow / ColumnNumberOverflow. Dimension parsing propagates the same errors, replacing the warn-and-continue path in get_dimension. The column step moved into push_column_letter so the uppercase and lowercase arms stay identical.

test_reference_beyond_grid_is_an_error covers one past the grid on each axis, references that overflow u32 entirely, the same through get_dimension, and the bottom-right cell XFD1048576, which still parses.

Touches the same get_dimension arm as #695; whichever lands second gets rebased.

@jmcnamara

Copy link
Copy Markdown
Collaborator

This PR is fixing the wrong thing. Rather than handling U32 overflow it should be handling invalid row/column dimensions and raising an error.

@jmcnamara jmcnamara self-assigned this Jul 29, 2026
@jmcnamara jmcnamara added the needs work for merge The PR needs some rework or clarification. No suitable for merge, yet. label Jul 29, 2026
Row and column accumulation is now checked, and references past
MAX_ROWS / MAX_COLUMNS return RowNumberOverflow / ColumnNumberOverflow.

Fixes tafia#694
@krickert
krickert force-pushed the fix/cellref-overflow branch from 81e41b3 to 15fad0f Compare July 29, 2026 15:42
@krickert

krickert commented Aug 2, 2026

Copy link
Copy Markdown
Author

Done.
Reworked the fix in 15fad0f: get_row_and_optional_column now validates against the grid and returns XlsxError::RowNumberOverflow (row > 1,048,576) or XlsxError::ColumnNumberOverflow (column > 16,384) instead of only guarding the u32 bounds.

The lenient warn! path in get_dimension is gone so dimension parsing propagates the error. The checked arithmetic is retained for the beyond-u32 case.

test_reference_beyond_grid_is_an_error covers one-past-grid on both axes, u32 overflow, and the in-bounds corner XFD1048576.

@krickert krickert changed the title fix(xlsx): check cell reference arithmetic for u32 overflow xlsx: error on cell references beyond the grid limits Aug 12, 2026
@krickert

krickert commented Aug 12, 2026

Copy link
Copy Markdown
Author

Reworked to reject invalid references as requested, let me know what you think.

krickert added a commit to ai-pipestream/calamine that referenced this pull request Aug 20, 2026
Brings pipestream-main from 0.36.0 + the original fix commits to
upstream/master at 0.36.1+ plus the post-review heads of the three open
upstream PRs:

  tafia#695  dimension normalisation (Dimensions::new)
  tafia#696  grid-limit errors from cell reference parsing
  tafia#697  Range::from_sparse returns Result<Range<T>, RangeError>

The tafia#697 head changes a public signature; the tree is byte-identical to
upstream/master with the three fix branches merged (verified by diff),
and the calamine test suite passes on that tree (46+164+65 tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs work for merge The PR needs some rework or clarification. No suitable for merge, yet.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cell reference parsing overflows u32 unchecked; MAX_ROWS/MAX_COLUMNS are warnings only

2 participants