-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Labels
Description
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/msoffcrypto/format/xls97.py", line 644, in is_encrypted
if not workbook.has_record(recordNameNum["FilePass"]):
File "/usr/local/lib/python3.10/dist-packages/msoffcrypto/format/xls97.py", line 418, in has_record
num, size = unpack("<HH", h)
struct.error: unpack requires a buffer of 4 bytes
Unfortunately I cannot share the file that triggers this exception.
But looking at xls97.py line 418, the code assumes that self.data.read(4) returns either exactly 4 bytes or nothing:
msoffcrypto-tool/msoffcrypto/format/xls97.py
Lines 411 to 423 in f727b42
| def has_record(self, target): | |
| pos = self.data.tell() | |
| while True: | |
| h = self.data.read(4) | |
| if not h: | |
| self.data.seek(pos) | |
| return False | |
| num, size = unpack("<HH", h) | |
| if num == target: | |
| self.data.seek(pos) | |
| return True | |
| else: | |
| self.data.read(size) |
I'm not sure what self.data there is but normally read(n) is guaranteed to return at most 4 bytes, not exactly 4 bytes.