Skip to content

calamine's .xls record parser panics and allocates without bound on damaged files (found by the sheets fuzz target) #1495

Closed

Description

@giswqs

The new sheets fuzz target (#1496) finds crashes in calamine 0.38's .xls reader past the compound-file container, which #1493 and #1496 now check before calamine runs. They are in its BIFF record and formula parsing, they exist on main with calamine 0.37 too, and two ten-minute runs found about 160 crashing inputs.

What crashes

Where (calamine 0.38) Inputs Cause
utils.rs:48 (read_u16), utils.rs:38 (read_u32) 75 s[..2] / s[..4] on a record shorter than the field
xls.rs:1531 (parse_formula) 44 &rgce[2..2 + cce] with cce past the record
xls.rs:838, :847, :850 (parse_defined_names) 21 r.data[3], r.data[4..] on a short NAME record
xls.rs:1871 (formula area refs) 5 rgce[4..8] on a short token
xls.rs:633 1 &stream[pos..] with a sheet offset past the Workbook stream
lib.rs:1051 (Range::from_sparse), reached from xls.rs:214 11 a dense grid for a cell at row/column up to 65535: allocations of 4 to 137 GB
xls.rs:667 (Dimensions) 4 end - start + 1 wraps when end < start; reserve asks for over 1 TB

Impact

  • Desktop, CLI, Python: the panics are caught by guarded (fix(deps): clear cargo audit vulnerabilities; guard .xls against looping sector chains #1493) and the file is refused. The allocations aren't panics: an allocation failure aborts the process, so a crafted .xls can still take the app down.
  • Browser: a panic can't be caught in wasm, so every row above crashes the web app.
  • calamine parses every sheet when it opens the workbook (xls.rs:214), so check_size in crates/data/src/sheets.rs can't help: it runs after the allocation. Its comment is also wrong: it says an .xls sheet "can't be larger than 65,536 × 256 cells", but BIFF8 cell records carry a 16-bit column, so calamine accepts columns up to 65,535.

Options

  1. Report upstream to tafia/calamine with minimized inputs (cargo +nightly fuzz tmin -O sheets …) and take the fix when it is released. calamine fixed the container-level allocations in 0.38 (RUSTSEC-2026-0436), so a report should land.
  2. Meanwhile, in RustGIS: read the Workbook stream ourselves (the container walk in check_compound already gets there) and refuse a Dimensions record with end < start, or cells past a bound, before calamine opens the file. That covers the allocations, which are the only crashes on desktop. The panics in the record parser are too spread out to mirror.

Reproduce: cd fuzz && cargo +nightly fuzz run -O sheets -- -max_total_time=300 -fork=4 -ignore_crashes=1 -ignore_ooms=1 (see fuzz/README.md).

Activity

  1. added
    bug
    on Nov 6, 2026
  2. added a commit that references this issue on Nov 9, 2026
    f18dbb2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions