From d110ce44933446eff800e6100fc54ccae821c4ad Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Wed, 13 May 2026 22:53:09 -0700 Subject: [PATCH] fix(clipboard): only read PNG signature bytes, not entire file Tighten _is_png_file() to read just the 8-byte PNG magic via path.open() + read(8), instead of slurping the entire image into memory only to check the prefix. --- hermes_cli/clipboard.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hermes_cli/clipboard.py b/hermes_cli/clipboard.py index a782c876b26..a6b6da7c06a 100644 --- a/hermes_cli/clipboard.py +++ b/hermes_cli/clipboard.py @@ -440,7 +440,8 @@ def _convert_to_png(path: Path) -> bool: def _is_png_file(path: Path) -> bool: """Return True when *path* starts with the PNG file signature.""" try: - return path.read_bytes().startswith(_PNG_SIGNATURE) + with path.open("rb") as f: + return f.read(len(_PNG_SIGNATURE)) == _PNG_SIGNATURE except OSError: return False