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:
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user