Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,15 @@ fn parse_formula(
// PtgExp: array/shared formula, ignore
debug!("ignoring PtgExp array/shared formula");
stack.push(formula.len());
// Ensure PtgExp carries a 4-byte operand for the row/column
// of the array or shared formula it points at.
if rgce.len() < 4 {
return Err(XlsError::Len {
expected: 4,
found: rgce.len(),
typ: "PtgExp",
});
}
rgce = &rgce[4..];
}
0x03..=0x11 => {
Expand Down
Binary file added tests/ptgexp-truncated-operand.xls
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,18 @@ fn biff5_formula_ptg_ref_643() {
assert_eq!(formulas.get_value((3, 1)), Some(&"$A$1".to_string()));
}

#[test]
fn test_xls_truncated_ptgexp() {
// Test for xls file with a truncated PtgExp token (array/shared formula)
// with 2 bytes instead of 4.
let mut excel: Xls<_> = wb("ptgexp-truncated-operand.xls");
let range = excel.worksheet_range("Tab 1").unwrap();
assert_eq!(range.get_size(), (23, 10));

let formulas = excel.worksheet_formula("Tab 1").unwrap();
assert_eq!(formulas.used_cells().count(), 22);
}

#[test]
fn biff5_rich_text_string() {
// This file uses RSTRING records, apparently produced by ABBYY FineReader.
Expand Down
Loading