Skip to content

xlsx: normalise reversed dimension refs - #695

Open
krickert wants to merge 4 commits into
tafia:masterfrom
ai-pipestream:fix/dimension-underflow
Open

xlsx: normalise reversed dimension refs#695
krickert wants to merge 4 commits into
tafia:masterfrom
ai-pipestream:fix/dimension-underflow

Conversation

@krickert

@krickert krickert commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #692.

A <dimension> whose end cell precedes its start, like C5:A1, underflowed the u32 subtractions in get_dimension: a debug build panics and a release build reports Dimensions::len() values around 1.8e19.

Dimensions::new now orders the corners so start <= end on both axes, and get_dimension goes through it, so a reversed ref parses the same as its ordered form. The MAX_ROWS / MAX_COLUMNS warnings compute from the normalised end corner. Dimensions::len() also widens to u64 before the + 1, so a full axis no longer overflows.

A Dimensions built as a struct literal still bypasses the ordering; making the fields private is left to the wider API discussion from the review.

Tests: test_reversed_dimension_is_normalised (reversed on both axes and on each axis alone) and test_dimensions_new_normalises_order.

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

Comment thread src/xlsx/mod.rs Outdated
Comment thread src/xlsx/mod.rs Outdated
Comment thread src/xlsx/mod.rs Outdated
Comment thread src/lib.rs Outdated
@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
@jmcnamara

jmcnamara commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

The commit message is too verbose, here and in the other PRs that you submitted. Please write these yourself to describe concisely what has been changed or what is being fixed. You should be able to do that (for most changes) in 1-2 lines in the body.

Reversed refs like C5:A1 underflowed the u32 extent arithmetic in
get_dimension and Dimensions::len. The constructor now stores the
corners ordered so start <= end on both axes.
@krickert
krickert force-pushed the fix/dimension-underflow branch from e90bebe to 51c130c Compare July 29, 2026 09:39
@krickert

Copy link
Copy Markdown
Author

Bad assumption on my part since ECMA-376 isn't clear. The closest authoritative statement is MS-OI29500 §2.1.1090, which says the standard doesn't clearly define what a valid cell range reference is, and that Office writes the smallest cell first. I've removed it. NBD since the normalization stands because it's a no-op on well-formed refs.

The constructor now normalizes the corners. The struct fields are still public, so a hand-built Dimensions { start, end } literal can bypass that. Should I make the fields private so that the invariant would be enforced?

Commit msg is now small. Working on the others.

Comment thread src/xlsx/mod.rs Outdated
Comment thread src/lib.rs Outdated
@jmcnamara

jmcnamara commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Should I make the fields private so that the invariant would be enforced?

That would be an API change so it would need a wider discussion. However, in my opinion they should be private and replaced by accessors, and there shouldn't be any len() method.

Also, once you have addressed the required changes can you mark them as resolved so it is clear that the work is done.

@krickert krickert changed the title fix(xlsx): normalise reversed <dimension> refs, make Dimensions::len total xlsx: normalise reversed dimension refs Aug 12, 2026
@krickert

krickert commented Aug 12, 2026

Copy link
Copy Markdown
Author

Review comments addressed, 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).
krickert added a commit to ai-pipestream/grpc-calamine that referenced this pull request Aug 20, 2026
cargo update -p calamine: pipestream-main f17b012 -> 4fddaec, which is
upstream 0.36.1+ with the post-review heads of tafia/calamine#695, #696
and #697. One behavior change reaches the server: a declared dimension
past the xlsx grid is now a hard ColumnNumberOverflow instead of a
warn-and-continue, so the dimension_wide fixture moves its declaration to
the in-grid maximum (A1:XFD1) to keep exercising the allocation path it
tests. Suite green: 38 streaming + 5 unit 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.

Reversed <dimension ref> underflows unchecked u32 subtraction in get_dimension and Dimensions::len

2 participants