Skip to content

Commit 386a745

Browse files
authored
Merge pull request #479 from sftse/malformed-format
Malformed format
2 parents 7e60cf7 + b5a8bf5 commit 386a745

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/xls.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,11 @@ impl<RS: Read + Seek> Xls<RS> {
338338
self.is_1904 = true
339339
}
340340
}
341-
// FORMATTING
341+
// 2.4.126 FORMATTING
342342
0x041E => {
343-
let (idx, format) = parse_format(&mut r, &encoding)?;
343+
let Ok((idx, format)) = parse_format(&mut r, &encoding) else {
344+
continue;
345+
};
344346
formats.insert(idx, format);
345347
}
346348
// XFS
@@ -910,17 +912,19 @@ fn parse_xf(r: &Record<'_>) -> Result<u16, XlsError> {
910912
/// Decode Format
911913
///
912914
/// See: https://learn.microsoft.com/ru-ru/openspecs/office_file_formats/ms-xls/300280fd-e4fe-4675-a924-4d383af48d3b
915+
/// 2.4.126
913916
fn parse_format(r: &mut Record<'_>, encoding: &XlsEncoding) -> Result<(u16, CellFormat), XlsError> {
914-
if r.data.len() < 4 {
917+
if r.data.len() < 5 {
915918
return Err(XlsError::Len {
916919
typ: "format",
917-
expected: 4,
920+
expected: 5,
918921
found: r.data.len(),
919922
});
920923
}
921924

922925
let idx = read_u16(r.data);
923926

927+
// TODO: check if this can be replaced with parse_string()
924928
let cch = read_u16(&r.data[2..]) as usize;
925929
let high_byte = r.data[4] & 0x1 != 0;
926930
r.data = &r.data[5..];

tests/malformed_format.xls

15.5 KB
Binary file not shown.

tests/test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2138,3 +2138,8 @@ fn test_string_ref() {
21382138
// second sheet is the same with a cell reference to the first sheet
21392139
range_eq!(xlsx.worksheet_range_at(1).unwrap().unwrap(), expected_range);
21402140
}
2141+
2142+
#[test]
2143+
fn test_malformed_format() {
2144+
let _xls: Xls<_> = wb("malformed_format.xls");
2145+
}

0 commit comments

Comments
 (0)