diff --git a/src/xls.rs b/src/xls.rs index a04fcbe..47e080a 100644 --- a/src/xls.rs +++ b/src/xls.rs @@ -338,9 +338,11 @@ impl Xls { self.is_1904 = true } } - // FORMATTING + // 2.4.126 FORMATTING 0x041E => { - let (idx, format) = parse_format(&mut r, &encoding)?; + let Ok((idx, format)) = parse_format(&mut r, &encoding) else { + continue; + }; formats.insert(idx, format); } // XFS @@ -910,17 +912,19 @@ fn parse_xf(r: &Record<'_>) -> Result { /// Decode Format /// /// See: https://learn.microsoft.com/ru-ru/openspecs/office_file_formats/ms-xls/300280fd-e4fe-4675-a924-4d383af48d3b +/// 2.4.126 fn parse_format(r: &mut Record<'_>, encoding: &XlsEncoding) -> Result<(u16, CellFormat), XlsError> { - if r.data.len() < 4 { + if r.data.len() < 5 { return Err(XlsError::Len { typ: "format", - expected: 4, + expected: 5, found: r.data.len(), }); } let idx = read_u16(r.data); + // TODO: check if this can be replaced with parse_string() let cch = read_u16(&r.data[2..]) as usize; let high_byte = r.data[4] & 0x1 != 0; r.data = &r.data[5..]; diff --git a/tests/malformed_format.xls b/tests/malformed_format.xls new file mode 100644 index 0000000..ee87abd Binary files /dev/null and b/tests/malformed_format.xls differ diff --git a/tests/test.rs b/tests/test.rs index 4faf6b7..bad9c3c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2138,3 +2138,8 @@ fn test_string_ref() { // second sheet is the same with a cell reference to the first sheet range_eq!(xlsx.worksheet_range_at(1).unwrap().unwrap(), expected_range); } + +#[test] +fn test_malformed_format() { + let _xls: Xls<_> = wb("malformed_format.xls"); +}