From 2a7d00d221d80a94be0b5a754cd42d2e3eeb88c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 14 Dec 2025 14:01:03 +0000 Subject: [PATCH] Fix UTF-8 decoding error when verifying signatures with international characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: GPG verification crashed with UnicodeDecodeError when signatures contained international characters (German ö, Turkish ü, etc.) in the signed content. Error: "'utf-8' codec can't decode byte 0xf6 in position 160" Root cause: subprocess.Popen was using default text decoding without handling encoding errors gracefully. Solution: 1. Changed LC_ALL/LANG from 'C' to 'C.UTF-8' to ensure GPG uses UTF-8 2. Added explicit encoding='utf-8' parameter to Popen 3. Added errors='replace' to replace invalid UTF-8 bytes instead of crashing This allows the verification to proceed even if GPG's output contains characters that don't decode cleanly, ensuring robustness with multilingual content. --- trace/crypto.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/trace/crypto.py b/trace/crypto.py index c342a94..8b4eaa4 100644 --- a/trace/crypto.py +++ b/trace/crypto.py @@ -46,8 +46,8 @@ class Crypto: # Force English output for consistent parsing across locales import os env = os.environ.copy() - env['LC_ALL'] = 'C' - env['LANG'] = 'C' + env['LC_ALL'] = 'C.UTF-8' # Use UTF-8 variant to handle international characters + env['LANG'] = 'C.UTF-8' proc = subprocess.Popen( ['gpg', '--verify'], @@ -55,6 +55,8 @@ class Crypto: stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, + encoding='utf-8', + errors='replace', # Replace invalid UTF-8 sequences instead of crashing env=env ) stdout, stderr = proc.communicate(input=signed_content, timeout=10)