Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Wrap piexif.dump call with try/except (#903)
Olga Bulat76e70d81e964
diff --git a/api/catalog/api/views/image_views.py b/api/catalog/api/views/image_views.pyindex 95fec62b5..c3dc304d3 100644--- a/api/catalog/api/views/image_views.py+++ b/api/catalog/api/views/image_views.py@@ -1,4 +1,5 @@import io+import structfrom django.conf import settingsfrom django.http.response import FileResponse, HttpResponse@@ -131,7 +132,14 @@ class ImageViewSet(MediaViewSet):watermarked, exif = watermark(image_url, image_info, params.data["watermark"])# Re-insert EXIF metadata.if exif:- exif_bytes = piexif.dump(exif)+ # piexif dump raises InvalidImageDataError which is a child class+ # of ValueError, and a struct error when the value is not+ # between -2147483648 and 2147483647+ # https://github.com/WordPress/openverse-api/issues/849+ try:+ exif_bytes = piexif.dump(exif)+ except (struct.error, ValueError):+ exif_bytes = Noneelse:exif_bytes = Noneimg_bytes = io.BytesIO()