Repository navigation
Prevents a crash when a data link reads a damaged spreadsheet - #3465
Closed
travisjhughes wants to merge 2 commits into
Closed
travisjhughes wants to merge 2 commits into
travisjhughes wants to merge 2 commits into
Conversation
calamine panics on a damaged .xls file: Sectors::get_chain follows the sector chain with an index that it does not check. The data link, the Table dialog and a paste read workbooks in message handlers on the UI thread, so the panic stops the app. Each of the five places that open a workbook now runs inside workbook_read, which gives a panic back as the read's error. Co-Authored-By: Claude
The tests build a damaged .xls file: the header, with a directory that starts in a sector which the empty sector table does not have. The sheet list and the rows are errors for the file in memory, on disk and as a picked file. A read that does not panic gives its own result. Co-Authored-By: Claude
travisjhughes
force-pushed
the
workbook-read-panic
branch
from
November 22, 2026 23:45
87df967 to
3da5888
Compare
Owner
|
Thanks! I merged #3466 (calamine 0.38.0) but I'm closing this one:
Generated by Claude Code |
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.
Change summary
A data link, the Table dialog and a paste read spreadsheet files with
calamine. A damaged.xlsfile makescalaminepanic, and these reads run in message handlers on the UI thread, so the app stops.With this change each spreadsheet read runs under
catch_unwind. A panic comes back as the error of the read (the spreadsheet reader stopped: <panic text>), which the callers already show.A file of 512 bytes is enough: the
.xlssignature and a header whose directory starts in a sector that the sector table does not have.What specifically changed
Two commits: the fix, then its tests.
src/app/annotation_data.rs:workbook_read(read)callsreadinsidecatch_unwindand makes an error from a panic. A wasm build aborts on a panic, so there it only callsread.workbook_metadata(a file on disk),workbook_metadata_bytes,workbook_first_sheet_rows, and the two branches ofread_tabular_file(a picked file in memory, a file on disk). The open and the read of the sheets are both inside, becausecalaminereads some parts only when a sheet is asked for.Why
calamine0.36.1 (the version inCargo.lock) and in 0.38.0 (the newest),Sectors::get_chain(src/cfb.rs) follows the sector chain withfats[sector_id as usize]and does not check the index. A file with an empty or short sector table panics there:index out of bounds.on_table_insert_apply), the Data Link Manager (on_data_link_insert), the refresh of a linked table (src/app/commands/table_cells.rs) and the paste of a workbook (src/app/shortcuts.rs).Testing
On main
0ca03459b(calamine0.36.1). I also ran the tests withcalamine0.38.0: the same results, and without the guard the same panic atcfb.rs:344.the spreadsheet reader stopped:; the header with nothing after it gives the same;workbook_metadataandread_tabular_fileare errors;read_tabular_fileis an error;calaminerefuses it);catch_unwindremoved fromworkbook_read, the three tests with the damaged file fail (the panic leaves the test).cargo test --workspace --locked --no-fail-fast,cargo check --workspace --all-targets, clippy, the wasm32 check, rustfmt on the changed files, the golden file): 7,729 passed and 1 failed before; 7,735 passed and 0 failed after. The 5 new tests are the only other difference. One test of main,picklocked_off_makes_locked_layer_objects_unselectable, failed in the run of main and passed in the run with this change; it also passed in three other runs on the same main, so it is not stable on main and not from this change. Warnings, the wasm32 check, clippy, rustfmt and the golden file are the same.cargo mutantson the diff: 27 mutants, 26 caught, 1 not viable, 0 missed.Not covered
catch_unwinddoes not stop those. The update ofcalamineto 0.38.0 repairs the allocation cases of the advisory.calamine. The index is not checked in 0.38.0. Thecalamineproject has a report of it (its issue 764), and its master branch (93e2e6b) gives an error for the damaged file of the tests. No release has that repair yet..xlsx,.xlsb,.ods): they go through the same guard, but I made no damaged file for them.Impact to Contributors
A new place that opens a workbook with
calamine: do it insideworkbook_read.Co-Authored-By: Claude