From 2ebc42f2cdd4ef6ff13a8d005113b2fff447e760 Mon Sep 17 00:00:00 2001 From: "Aaron D. Lee" Date: Sun, 11 Jan 2026 13:40:12 -0500 Subject: [PATCH] Fix EXIF viewer breaking on binary MakerNote fields Pentax and other cameras have binary EXIF fields (MakerNote, etc.) that contain raw bytes. The previous code used errors="replace" which still produced strings with replacement characters that broke JSON parsing. Now properly detect non-printable binary data and display as "" instead. Co-Authored-By: Claude Opus 4.5 --- src/stegasoo/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/stegasoo/utils.py b/src/stegasoo/utils.py index e47c25d..b8b4051 100644 --- a/src/stegasoo/utils.py +++ b/src/stegasoo/utils.py @@ -66,9 +66,15 @@ def read_image_exif(image_data: bytes) -> dict: # Convert bytes to string if possible elif isinstance(value, bytes): try: - result[tag] = value.decode("utf-8", errors="replace").strip("\x00") - except Exception: - result[tag] = f"<{len(value)} bytes>" + # Try to decode as ASCII/UTF-8 text + decoded = value.decode("utf-8", errors="strict").strip("\x00") + # Only keep if it looks like printable text + if decoded.isprintable() or all(c.isspace() or c.isprintable() for c in decoded): + result[tag] = decoded + else: + result[tag] = f"<{len(value)} bytes binary>" + except (UnicodeDecodeError, Exception): + result[tag] = f"<{len(value)} bytes binary>" # Handle tuples of IFDRational elif isinstance(value, tuple) and value and hasattr(value[0], "numerator"): result[tag] = [float(v) for v in value]