Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed format #479

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ impl<RS: Read + Seek> Xls<RS> {
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
Expand Down Expand Up @@ -910,17 +912,19 @@ fn parse_xf(r: &Record<'_>) -> Result<u16, XlsError> {
/// 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..];
Expand Down
Binary file added tests/malformed_format.xls
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}