From 2f56c5dc242f9c827eb536ee36bcea0b3bd17dd0 Mon Sep 17 00:00:00 2001 From: yc111233 Date: Thu, 2 Apr 2026 00:56:07 +0800 Subject: [PATCH 1/2] fix: decrypt raises 'Ciphertext too short' on plaintext files shorter than 4 bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The decrypt() method checked ciphertext length before checking the magic header. This caused plaintext files shorter than 4 bytes (including empty files) to raise InvalidMagicError('Ciphertext too short') before the 'is this plaintext?' check could return them as-is. Fix: swap the order — check if content starts with OVE1 magic first, then only check length for actual encrypted content. This fixes failures when append_file() reads an empty messages.jsonl session file and tries to decrypt it. --- openviking/crypto/encryptor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openviking/crypto/encryptor.py b/openviking/crypto/encryptor.py index ca6609ebb..cf99a78e3 100644 --- a/openviking/crypto/encryptor.py +++ b/openviking/crypto/encryptor.py @@ -108,14 +108,16 @@ async def decrypt(self, account_id: str, ciphertext: bytes) -> bytes: Returns: Decrypted plaintext content """ - # 1. Check magic number - if len(ciphertext) < MAGIC_LENGTH: - raise InvalidMagicError("Ciphertext too short") - + # 1. Check magic number (check prefix first, before length) + # This ensures plaintext files (including empty/short ones) are + # returned as-is instead of raising "Ciphertext too short". if not ciphertext.startswith(MAGIC): # Unencrypted file, return directly return ciphertext + if len(ciphertext) < MAGIC_LENGTH: + raise InvalidMagicError("Ciphertext too short") + try: # 2. Parse Envelope ( From d35143f090cc67a38d5bdc6fe5c7720de426b8c5 Mon Sep 17 00:00:00 2001 From: yc111233 <109650216+yc111233@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:57:57 +0800 Subject: [PATCH 2/2] fix: add strict=True to zip() in summarizer (B905 lint) --- openviking/utils/summarizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openviking/utils/summarizer.py b/openviking/utils/summarizer.py index 805b7a3d2..dbc496a31 100644 --- a/openviking/utils/summarizer.py +++ b/openviking/utils/summarizer.py @@ -55,7 +55,7 @@ async def summarize( enqueued_count = 0 telemetry = get_current_telemetry() - for uri, temp_uri in zip(resource_uris, temp_uris): + for uri, temp_uri in zip(resource_uris, temp_uris, strict=True): # Determine context_type based on URI context_type = "resource" if uri.startswith("viking://memory/"):