mirror of
https://github.com/wiltodelta/remove-ai-watermarks.git
synced 2026-07-11 18:46:32 +02:00
fix(metadata): guard get_ai_metadata PIL open against non-OSError
get_ai_metadata opened the file with PIL unguarded, so a HEIC (or any format PIL can't open without optional plugins) raised UnidentifiedImageError instead of falling through to the binary scan -- unlike has_ai_metadata, which already guards. Wrap the open in except Exception and continue to the C2PA/IPTC path. Regression test feeds an unopenable .heic shell and asserts no raise. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,13 @@ class TestGetAiMetadata:
|
||||
assert meta["parameters"].endswith("…")
|
||||
assert len(meta["parameters"]) <= 205
|
||||
|
||||
def test_unopenable_file_does_not_raise(self, tmp_path: Path):
|
||||
# PIL can't open HEIC without pillow-heif; get_ai_metadata must fall
|
||||
# through to the binary scan, not propagate UnidentifiedImageError.
|
||||
path = tmp_path / "iphone.heic"
|
||||
path.write_bytes(b"\x00\x00\x00\x18ftypheic" + b"\x00" * 64)
|
||||
assert get_ai_metadata(path) == {}
|
||||
|
||||
|
||||
@pytest.mark.skipif(not SAMPLES_DIR.exists(), reason="data/samples not present")
|
||||
class TestGetAiMetadataRealSample:
|
||||
|
||||
Reference in New Issue
Block a user