Merge pull request #13028 from AUTOMATIC1111/fallback-invalid-exif

Add Fallback at images.read_info_from_image if exif data was invalid
This commit is contained in:
AUTOMATIC1111 2023-09-09 09:21:18 +03:00 committed by GitHub
commit 9e58e11ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -724,7 +724,12 @@ def read_info_from_image(image: Image.Image) -> tuple[str | None, dict]:
geninfo = items.pop('parameters', None)
if "exif" in items:
exif = piexif.load(items["exif"])
exif_data = items["exif"]
try:
exif = piexif.load(exif_data)
except OSError:
# memory / exif was not valid so piexif tried to read from a file
exif = None
exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'')
try:
exif_comment = piexif.helper.UserComment.load(exif_comment)