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

Detect password protected xls files #386

Merged
merged 1 commit into from
Dec 19, 2023
Merged
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
3 changes: 2 additions & 1 deletion src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ impl<RS: Read + Seek> Xls<RS> {
for record in records {
let mut r = record?;
match r.typ {
0x0012 if read_u16(r.data) != 0 => return Err(XlsError::Password),
// 2.4.117 FilePass
0x002F if read_u16(r.data) != 0 => return Err(XlsError::Password),
// CodePage
0x0042 => {
if self.options.force_codepage.is_none() {
Expand Down
Binary file added tests/issue_385.xls
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,3 +1514,16 @@ fn issue_374() {

assert_eq!("sheetjs", cell_text);
}

#[test]
fn issue_385() {
let path = format!("{}/tests/issue_385.xls", env!("CARGO_MANIFEST_DIR"));

assert!(
matches!(
open_workbook::<Xls<_>, std::string::String>(path),
Err(calamine::XlsError::Password)
),
"Is expeced to return XlsError::Password error"
);
}