Repository navigation
Conversation
Fixed issue where three malformed xlsb inputs caused a panic instead of an error: a BrtCellIsst record whose shared string index is past the shared strings table, a sheet whose relationship id is not in workbook.bin.rels, and a BrtWsDim record shorter than 16 bytes. Fixes tafia#799.
jmcnamara
requested changes
Nov 13, 2026
| ], | ||
| &mut buf, | ||
| )?; | ||
| // The buffer can be longer than the record, since it also held the |
Collaborator
There was a problem hiding this comment.
This comment is confusing. Maybe something like:
// The buffer is reused for each record and is never shrunk, so it can be
// longer than this record. Check the record length instead.
Comment on lines
+312
to
+318
| let target = | ||
| relationships | ||
| .get(&*relid) | ||
| .ok_or_else(|| XlsbError::Unrecognized { | ||
| typ: "sheet relationship id", | ||
| val: relid.to_string(), | ||
| })?; |
Collaborator
There was a problem hiding this comment.
Might be better as:
let Some(target) = relationships.get(&*relid) else { return Err(...) };| // BrtCellIsst | ||
| let isst = read_usize(&self.buf[8..12]); | ||
| DataRef::SharedString(&self.strings[isst]) | ||
| let string = self.strings.get(isst).ok_or(XlsbError::Unrecognized { |
Collaborator
There was a problem hiding this comment.
I think .ok_or() will allocate every time. This would be better as ok_or_else():
let string = self.strings.get(isst).ok_or_else(|| XlsbError::Unrecognized {
typ: "shared string index",
val: isst.to_string(),
})?;Or as an "let else":
let Some(string) = self.strings.get(isst) else {
return Err(XlsbError::Unrecognized {
typ: "shared string index",
val: isst.to_string(),
});
};
DataRef::SharedString(string)
Collaborator
|
Thanks for the fixes. There are other similar issues in the code that you could also fix in passing (after double checking):
|
Apply the review suggestions and check the length of BrtWbProp, BrtBundleSh, the cell records and the formula records before they are indexed. The record buffer is reused and never shrunk, so a short cell record was read with the bytes of an earlier record.
Author
|
Thanks for the review. Changes are in 6fb85db:
Four new fixtures and tests cover an empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed issue where three malformed xlsb inputs caused a panic instead of an error. Each one now returns
XlsbError::Unrecognized, the variant theBrtNamefix in #761 uses:BrtCellIsstrecord whose shared string index is past the shared strings table, or in a workbook with no shared strings part (self.strings[isst]).workbook.bin.rels(relationships[&*relid]).BrtWsDimrecord shorter than 16 bytes (&buf[..16]). The check is on the record length and not on the buffer, because the buffer also held the skippedBrtBeginSheet/BrtWsProprecords and can be longer than the record.Related issue
Fixes #799.
Testing
Three test files under
tests/, one per case, and a test for each intests/test.rs. Without the change each test panics at the line named in the issue; with it they pass.The files are hand-edited, since the reporter's seed files are not posted yet. I took
tests/unknown_record_before_names.xlsb, removed its unknown workbook record, and changed one thing per file:shared_string_index_out_of_range.xlsb: added aBrtRowHdrand aBrtCellIsstwith index 5 to the sheet. The workbook has nosharedStrings.bin.sheet_relationship_not_found.xlsb: theBrtBundleShrelationship id isrId9instead ofrId1.short_ws_dim_record.xlsb: theBrtWsDimrecord is 8 bytes instead of 16.If the reporter's files show a different shape for any of these, I am happy to swap them in.
Checklist
cargo test --all-featurespasses.cargo fmt -- --checkpasses.cargo clippy --all-targets --all-features -- -Dwarningspasses.Other information
Not run locally:
cargo +1.88 check, thewasm32-unknown-unknowncheck andtypos, as I do not have those installed. The change only usesslice::getandOption::ok_or.