From f593cbfec417a3ea40589fe64e7f8806c9a81e5a Mon Sep 17 00:00:00 2001 From: AngelBottomless Date: Sun, 3 Sep 2023 21:07:36 +0900 Subject: [PATCH] fallback if exif data was invalid --- modules/images.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/images.py b/modules/images.py index eb6447338..8512a46ec 100644 --- a/modules/images.py +++ b/modules/images.py @@ -718,7 +718,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)