Skip to content

Runtime panic during loading of a spreadsheet saved with Excelize #330

Description

@fgimian

Hey there, the attached spreadsheet causes a runtime panic with the library.

Book1.xlsx

Here's the basic code to reproduce it in Rust:

use std::path::Path;

fn main() {
    umya_spreadsheet::reader::xlsx::read(Path::new("Book1.xlsx")).expect("cant read it");
}

And the output:

thread 'main' (19800) panicked at C:\Users\Fots\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\umya-spreadsheet-3.0.0\src\reader\xlsx\workbook.rs:85:18:
called `Result::unwrap()` on an `Err` value: NotFound
stack backtrace:
   0: std::panicking::panic_handler
             at /rustc/ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96/library\std\src\panicking.rs:689
   1: core::panicking::panic_fmt
             at /rustc/ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96/library\core\src\panicking.rs:80
   2: core::result::unwrap_failed
             at /rustc/ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96/library\core\src\result.rs:1867
   3: enum2$<core::result::Result<ref_mut$<umya_spreadsheet::structs::worksheet::Worksheet>,enum2$<umya_spreadsheet::structs::error::XlsxError> > >::unwrap
             at C:\Users\Fots\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:1233
   4: umya_spreadsheet::reader::xlsx::workbook::read<std::fs::File>
             at C:\Users\Fots\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\umya-spreadsheet-3.0.0\src\reader\xlsx\workbook.rs:85
   5: umya_spreadsheet::reader::xlsx::read_reader_with_source<std::fs::File>
             at C:\Users\Fots\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\umya-spreadsheet-3.0.0\src\reader\xlsx.rs:72
   6: umya_spreadsheet::reader::xlsx::read_reader<std::fs::File>
             at C:\Users\Fots\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\umya-spreadsheet-3.0.0\src\reader\xlsx.rs:62
   7: umya_spreadsheet::reader::xlsx::read<ref$<std::path::Path> >
             at C:\Users\Fots\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\umya-spreadsheet-3.0.0\src\reader\xlsx.rs:126
   8: problem::main
             at .\src\main.rs:4
   9: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at C:\Users\Fots\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\problem.exe .\Book1.xlsx` (exit code: 101)

After investigating further, changing the following line in xl/workbook.xml as follows resolves the problem:

-        <sheet name="Sheet1" sheetId="1" state="visible" r:id="rId2"></sheet>
+        <sheet name="Sheet1" sheetId="1" state="visible" r:id="rId2" />

This is the most minimal reproduction I can create from my original spreadsheet. As per other issues, the failure to load is only one of the issues here. Rust libraries really shouldn't be panicking during runtime during a failed operation. I can see this particular unwrap at https://github.com/MathNya/umya-spreadsheet/blob/master/src/reader/xlsx/workbook.rs#L85 but the codebase seems to use unwrap liberally throughout which honestly makes me very nervous when using it. Obviously some uses of unwrap are OK if they simply can never fail, but there do seem to be many cases like this where unwrap can cause a runtime panic.

Huge thanks in advance!
Fotis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions