Skip to content

fix(data): reject malformed ODS nesting and scope ZIP offset inference - #2389

Open
deniial00 wants to merge 1 commit into
opengeos:mainfrom
deniial00:fix-spreadsheet-ods-nesting
Open

deniial00 wants to merge 1 commit into
opengeos:mainfrom
deniial00:fix-spreadsheet-ods-nesting

Conversation

@deniial00

@deniial00 deniial00 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Reject nested ODS cells and annotations before the workbook reader runs so malformed nesting cannot evade the spreadsheet memory limits. Ordinary annotations and formatted cell text still import.

Keep ZIP directory-offset inference specific to spreadsheets. KMZ and other ZIP readers once again use the offsets recorded in the archive.

The ODS check applies to the shared desktop, web, CLI, Python and phone readers. No commands, dependencies or saved formats change. Rejected files are left unchanged.

Testing

  • cargo xtask ci and pre-commit run --all-files passed.
  • RUSTFLAGS='-D warnings' cargo build --locked --target wasm32-unknown-unknown -p rustgis-web passed.
  • Regression tests cover malformed ODS nesting, ordinary annotated cells, and the spreadsheet-only ZIP offset behavior.

UI evidence

No visible UI change.

Related issue

Follow-up to #2359. Part of #2008.

Summary by CodeRabbit

  • Bug Fixes
    • Spreadsheet files with an unrecorded ZIP preamble or a digital-signature trailer are now handled more reliably.
    • Malformed spreadsheets containing nested table cells or nested annotations are now rejected during validation. Ordinary annotated text remains readable.

- Refuse nested cells and annotations during ODS preflight.
- Preserve the recorded ZIP directory lookup for non-spreadsheet readers.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Spreadsheet reads now use adjusted ZIP central-directory discovery in defined cases. ODS preflight rejects nested table cells and annotations while preserving ordinary annotated text.

Changes: Spreadsheet read checks

Layer / File(s) Summary
Spreadsheet ZIP directory discovery
crates/data/src/zip.rs
For nonempty spreadsheet archives, directory discovery can infer a start location and adjust local-header offsets. A test verifies that spreadsheet reads accept an unrecorded preamble while ordinary reads reject it.
ODS nesting preflight
crates/data/src/sheets/ods.rs, crates/data/src/sheets.rs
ODS preflight rejects nested table cells and annotations. Tests cover those rejections and confirm that ordinary annotated text with a span remains readable without report messages.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • opengeos/RustGIS#2008 — The PR adds ODS preflight checks related to the issue’s task of limiting repeated-cell expansion before worksheet reading.

Possibly related PRs

Suggested reviewers: giswqs, mavrick-f

Merge Risk: Minimal · up to 29b98

This change rejects malformed nested ODS files before they are read and limits ZIP offset inference to spreadsheets. No actionable merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: rejecting malformed ODS nesting and scoping ZIP offset inference to spreadsheets. Both match the raw summary and the PR objectives. The title uses a conventi…
Description check Passed The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the ODS nesting rejection and the ZIP offset scoping. The Testin…
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: Title check

Explanation

The title names the two changes in the PR: rejecting malformed ODS nesting and scoping ZIP offset inference to spreadsheets. Both match the raw summary and the PR objectives. The title uses a conventional commit prefix and stays within one sentence. It is 70 characters long, which is slightly above the common 72-character guideline but still readable.

Full details: Description check

Explanation

The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the ODS nesting rejection and the ZIP offset scoping. The Testing section lists the commands run and the regression tests. The UI evidence section keeps the required 'No visible UI change.' line. The Related issue section cites #2359 and #2008. The template's HTML comments were removed, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • 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

A rabbit checks the cells with care,
No nested notes may hide in there.
A ZIP preamble passes the sheet,
While ordinary reads stay neat.
Span and text can still appear,
The bunny hops, its workbook clear.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 07e5eb1f-63db-40f6-b352-1045c3a64962
Commits

Reviewing files that changed from the base of the PR and between 3e12f42 and 29b989a.

Files selected for processing: 3

  • crates/data/src/sheets.rs
  • crates/data/src/sheets/ods.rs
  • crates/data/src/zip.rs

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

Comment thread crates/data/src/zip.rs
// A digital-signature trailer may separate the directory from EOCD. Match
// calamine's ZIP lookup: otherwise take the first central header from p.
(p..central_end).find(|start| u32_at(bytes, *start) == Some(0x0201_4B50)).ok_or_else(bad)?
recorded

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior change for non-spreadsheet ZIP readers (KMZ and others). Before this PR, read inferred a preamble for any archive whose recorded offsets missed it. Now an archive with unrecorded leading bytes fails with not a zip archive (or a damaged one). The archive is valid, so that message is misleading, and nothing tells the user why the file was refused.

The PR says this is intended, so I'm not calling it a bug. Please either give this path a clearer error (for example, "the recorded directory offset doesn't match the archive layout; leading bytes aren't supported") or name the regression in the PR description. Confidence: medium. I didn't find a fixture that covers a KMZ-style archive with a preamble.

Comment thread crates/data/src/sheets.rs
for cell in ["<table:table-cell/>", "<table:covered-table-cell/>"] {
refused_before_calamine(&book(cell), "nested cell");
}
let clean = book("<office:annotation><text:p>note</text:p></office:annotation><text:p><text:span>value</text:span></text:p>");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage gap on the "clean input gives no notice" side. The nested-annotation check depends on the open annotation being cleared at its matching End. This clean case only has one annotation per cell, so a regression that rejects two sibling annotations would not be caught.

Suggest adding a case such as <text:p>a<office:annotation><text:p>x</text:p></office:annotation>b<office:annotation><text:p>y</text:p></office:annotation></text:p> that must import with no notices. Confidence that the current code handles it correctly: high. The gap is in the tests.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base AGENTS.md, and the surrounding code in ods.rs and zip.rs. I found no confirmed bugs, security issues, or performance regressions. Two inline comments are posted.

Bugs

  • None found. The ODS Event::Start checks are sound because expand_empty_elements = true turns <table:table-cell/> into a Start/End pair. The Start-only nested-cell check therefore covers self-closing cells. Sibling annotations clear correctly at their matching End. The spreadsheet branch of the ZIP central-directory lookup matches the old logic.

Security

  • None found.

Performance

  • None new. The (recorded..end).find fallback scan has no Cancel check, but it was already there before this PR.

Quality

  • zip.rs:263 (inline, medium confidence): non-spreadsheet readers such as KMZ no longer infer unrecorded preambles. An archive that used to open now fails with the generic "not a zip archive (or a damaged one)" message, and no notice explains it. The PR describes this as intended, so I raised it as a message-quality and disclosure concern, not a bug. No fixture covers it.

AGENTS.md

  • "Test both ways" (sheets.rs:946, inline, high confidence in the code, gap in coverage): the clean-input test has only one annotation per cell. Two sibling annotations in one cell are not tested, so a false rejection would go uncaught.
  • No other rule violations seen. Rejections go through DataError::Format, which is an error with the reason attached, as "unusable results are errors" requires.

Prior review threads: none. Nothing was left alone for that reason.

Change size

Compared: the whole PR against main (merge base 89220ea to PR head 29b989a).

Measure Value
Files changed 3 (added 0, modified 3, removed 0, renamed 0)
Size before 106.7 KB
Size after 108.3 KB
Total size change +1.6 KB
Path Before After Change
crates/data/src/sheets.rs 76.1 KB 77.2 KB +1.0 KB
crates/data/src/sheets/ods.rs 8.6 KB 8.9 KB +339 B
crates/data/src/zip.rs 21.9 KB 22.2 KB +239 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2389/
Web app https://preview.rustgis.app/pr-2389/app/
Commit 29b989a

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

This branch has not been deployed

No deployments
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