You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calamine's .xls record parser panics and allocates without bound on damaged files (found by the sheets fuzz target) #1495
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
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
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.
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
fix(data): follow only calamine's .xls chains; add a sheets fuzz targ…
Data: validate XLS BIFF records before parsing (opengeos#1664)