mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 06:24:39 +00:00
craft-xlsx: review fix: skipped column records count toward the column cap
A sheet of 16,385 reversed or out-of-grid BrtColInfo ranges was skipped one by one without reaching the cap, since only kept columns were counted. Every column record now counts.
This commit is contained in:
@@ -840,6 +840,8 @@ pub(crate) fn worksheet(
|
||||
let mut sheet = SheetPart::default();
|
||||
let mut data = false;
|
||||
let mut data_seen = false;
|
||||
// Every BrtColInfo counts toward the cap, a skipped one too.
|
||||
let mut column_records = 0usize;
|
||||
let mut row: Option<Row> = None;
|
||||
let mut col = None;
|
||||
// The default row height in twips: a row of another height has `ht` even when it was not set
|
||||
@@ -992,15 +994,16 @@ pub(crate) fn worksheet(
|
||||
if data_seen {
|
||||
return Err(invalid("column after worksheet data"));
|
||||
}
|
||||
if column_records >= MAX_COLUMNS {
|
||||
return Err(Error::TooLarge(format!("XLSB exceeds {MAX_COLUMNS} column records")));
|
||||
}
|
||||
column_records += 1;
|
||||
let column = column(&mut b)?;
|
||||
b.finish()?;
|
||||
let Some(column) = column else {
|
||||
warnings.warn("invalid XLSB column ranges were skipped");
|
||||
continue;
|
||||
};
|
||||
if sheet.columns.len() >= MAX_COLUMNS {
|
||||
return Err(Error::TooLarge(format!("XLSB exceeds {MAX_COLUMNS} column records")));
|
||||
}
|
||||
sheet.columns.push(column);
|
||||
}
|
||||
176 => {
|
||||
|
||||
@@ -1046,6 +1046,9 @@ fn damaged_sizes_are_skipped_or_refused() {
|
||||
// More column records than columns are refused.
|
||||
let many = [&record(390, &[])[..], &col_info(0, 0, 2321, 0, 0).repeat(16_385), &record(391, &[])].concat();
|
||||
assert!(matches!(sizes_of(&file(&sized_sheet(&many, &[]))), Err(Error::TooLarge(_))));
|
||||
// Skipped (reversed) column records count toward that cap too.
|
||||
let reversed = [&record(390, &[])[..], &col_info(5, 4, 2321, 0, 0).repeat(16_385), &record(391, &[])].concat();
|
||||
assert!(matches!(sizes_of(&file(&sized_sheet(&reversed, &[]))), Err(Error::TooLarge(_))));
|
||||
// A sheet format or column after the data, or a record of the wrong size, fails the read.
|
||||
for (why, sheet) in [
|
||||
("format after data", worksheet(&[], &ws_fmt_info(u32::MAX, 8, 285, 0, [0, 0]))),
|
||||
|
||||
Reference in New Issue
Block a user