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:
test-user
2026-05-24 16:19:15 -07:00
parent af787fd8d6
commit f36320ff39
2 changed files with 22 additions and 9 deletions
+7
View File
@@ -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: