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.
This commit is contained in:
teknium1 2026-05-13 22:53:09 -07:00 committed by Teknium
parent 8db544b4d0
commit d110ce4493

View file

@ -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