Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3de82bb

Browse files
authored
Gracefully handle failing to thumbnail images (#16211)
1 parent a2e0d4c commit 3de82bb

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

changelog.d/16211.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where uploading images would fail if we could not generate thumbnails for them.

synapse/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
import sys
2222
from typing import Any, Dict
2323

24+
from PIL import ImageFile
25+
2426
from synapse.util.rust import check_rust_lib_up_to_date
2527
from synapse.util.stringutils import strtobool
2628

29+
# Allow truncated JPEG images to be thumbnailed.
30+
ImageFile.LOAD_TRUNCATED_IMAGES = True
31+
2732
# Check that we're not running on an unsupported Python version.
2833
#
2934
# Note that we use an (unneeded) variable here so that pyupgrade doesn't nuke the

synapse/media/media_repository.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ async def create_content(
214214
user_id=auth_user,
215215
)
216216

217-
await self._generate_thumbnails(None, media_id, media_id, media_type)
217+
try:
218+
await self._generate_thumbnails(None, media_id, media_id, media_type)
219+
except Exception as e:
220+
logger.info("Failed to generate thumbnails: %s", e)
218221

219222
return MXCUri(self.server_name, media_id)
220223

0 commit comments

Comments
 (0)