Skip to content

Commit

Permalink
Detect password protected xls files
Browse files Browse the repository at this point in the history
  • Loading branch information
saks committed Dec 18, 2023
1 parent dd694e9 commit ce55340
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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"
);
}

0 comments on commit ce55340

Please sign in to comment.