From 883be60fc5b58493a2d52275626860a1f4a0af4e Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Wed, 15 Apr 2026 15:53:37 +0200 Subject: [PATCH] bugfix: attribute error on exception object + more 7z header tests --- releases/Next-ChangeLog.md | 1 + shared/compat7z.py | 21 ++++----- testing/test_backup.py | 87 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/releases/Next-ChangeLog.md b/releases/Next-ChangeLog.md index 6d532025..e1de2b3c 100644 --- a/releases/Next-ChangeLog.md +++ b/releases/Next-ChangeLog.md @@ -11,6 +11,7 @@ This lists the new changes that have not yet been published in a normal release. - Bugfix: "Send Password" menu item inside Notes & Passwords visibility reversed - Bugfix: Yikes when using "Send Password" on entry with password None field - Bugfix: Do not show "Saving..." UX after failed Notes & Passwords import +- Bugfix: Incorrect error message caused by error in Verify/Decrypt Backup # Mk Specific Changes diff --git a/shared/compat7z.py b/shared/compat7z.py index 55b6b880..45124057 100644 --- a/shared/compat7z.py +++ b/shared/compat7z.py @@ -51,9 +51,7 @@ def decode_utf_16_le(s): ''' def read_var64(f): - ''' - Decode their silly 64-bit encoding. - ''' + # Decode their silly 64-bit encoding. first = ord(f.read(1)) if first < 128: return first @@ -113,22 +111,21 @@ def check_file_headers(f): if sh.size > 10000: raise ValueError("Second header too big") - # capture this spot - # TODO 'data_start' unused - data_start = f.tell() # expect 0x20 + # FileHeader.read() always reads exactly calcsize('<6sBBL') = 12 bytes + # SectionHeader.read() always reads exactly calcsize(' mismatch --> error + corrupted = bytearray(conts) + corrupted[12] ^= 0xFF + with open(fn, "wb") as f: + f.write(bytes(corrupted)) + + with pytest.raises(AssertionError): + verify_backup_file(fname) + + title, story = cap_story() + assert "Second header has wrong CRC" in story + + # Set sh.size (offset 8 in SectionHeader = file bytes 20-27) to > 10000, + # then update fh.crc (file bytes 8-11) so the CRC check passes first. + fh_bytes = bytearray(conts[:12]) + sh_bytes = bytearray(conts[12:32]) + struct.pack_into('