From 0329ed452f2665382ad55fe7215ff71e1b0d9679 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 30 Aug 2023 12:17:26 +0100 Subject: [PATCH 1/3] Gracefully handle failing to thumbnail images --- synapse/__init__.py | 5 +++++ synapse/media/media_repository.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/synapse/__init__.py b/synapse/__init__.py index 2f9c22a83352..4a9bbc4d57b7 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -21,9 +21,14 @@ import sys from typing import Any, Dict +from PIL import ImageFile + from synapse.util.rust import check_rust_lib_up_to_date from synapse.util.stringutils import strtobool +# Allow truncated JPEG images to be thumbnailed. +ImageFile.LOAD_TRUNCATED_IMAGES = True + # Check that we're not running on an unsupported Python version. # # Note that we use an (unneeded) variable here so that pyupgrade doesn't nuke the diff --git a/synapse/media/media_repository.py b/synapse/media/media_repository.py index 4b750c700b89..1b7b014f9ac2 100644 --- a/synapse/media/media_repository.py +++ b/synapse/media/media_repository.py @@ -214,7 +214,10 @@ async def create_content( user_id=auth_user, ) - await self._generate_thumbnails(None, media_id, media_id, media_type) + try: + await self._generate_thumbnails(None, media_id, media_id, media_type) + except Exception as e: + logger.info("Failed to generate thumbnails: %s", e) return MXCUri(self.server_name, media_id) From c9d811bf534adb927dd883865322a0784d9fd7fc Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 30 Aug 2023 12:19:15 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/16211.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/16211.bugfix diff --git a/changelog.d/16211.bugfix b/changelog.d/16211.bugfix new file mode 100644 index 000000000000..94b9337c1497 --- /dev/null +++ b/changelog.d/16211.bugfix @@ -0,0 +1 @@ +Fix bug where uploading images would fail if we could not generate thumbanils for them. From c868fa1f1658f3bae00a86ffbb78b295ce58add5 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 30 Aug 2023 14:03:39 +0100 Subject: [PATCH 3/3] Update changelog.d/16211.bugfix Co-authored-by: David Robertson --- changelog.d/16211.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/16211.bugfix b/changelog.d/16211.bugfix index 94b9337c1497..ab1816386c1c 100644 --- a/changelog.d/16211.bugfix +++ b/changelog.d/16211.bugfix @@ -1 +1 @@ -Fix bug where uploading images would fail if we could not generate thumbanils for them. +Fix a long-standing bug where uploading images would fail if we could not generate thumbnails for them.