From d6de45a5c5c841f501a6865392bd23948ac62f59 Mon Sep 17 00:00:00 2001 From: schmop Date: Wed, 23 Nov 2022 15:23:44 +0100 Subject: [PATCH 1/4] Fix crash whenon admin media list api when info is None --- synapse/storage/databases/main/room.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index 4fbaefad7304..51ed9171239f 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -912,7 +912,7 @@ def _get_media_mxcs_in_room_txn( event_json = db_to_json(content_json) content = event_json["content"] content_url = content.get("url") - thumbnail_url = content.get("info", {}).get("thumbnail_url") + thumbnail_url = (content.get("info") or {}).get("thumbnail_url") for url in (content_url, thumbnail_url): if not url: From 4445c0df3a355d697803565198420b16a9788517 Mon Sep 17 00:00:00 2001 From: schmop Date: Wed, 23 Nov 2022 16:01:08 +0100 Subject: [PATCH 2/4] Add changelog for issue 14536 --- changelog.d/14536.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14536.bugfix diff --git a/changelog.d/14536.bugfix b/changelog.d/14536.bugfix new file mode 100644 index 000000000000..150da85d4d93 --- /dev/null +++ b/changelog.d/14536.bugfix @@ -0,0 +1 @@ +Fix a bug in the media admin room list API crashing when an image event exists with broken thumbnail information. Contributed by @schmop. \ No newline at end of file From ebaa0d9e155fb52259b2932144c49ed4f2a69fd6 Mon Sep 17 00:00:00 2001 From: schmop Date: Wed, 23 Nov 2022 16:35:54 +0100 Subject: [PATCH 3/4] Rename changelog file name to match pull request id --- changelog.d/{14536.bugfix => 14537.bugfix} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{14536.bugfix => 14537.bugfix} (100%) diff --git a/changelog.d/14536.bugfix b/changelog.d/14537.bugfix similarity index 100% rename from changelog.d/14536.bugfix rename to changelog.d/14537.bugfix From 28dd9e4844b87614eb33954a0c9b7efdfdb6db3c Mon Sep 17 00:00:00 2001 From: schmop Date: Wed, 23 Nov 2022 16:41:40 +0100 Subject: [PATCH 4/4] Add strict type check in 'content.info' property for dictionaries in media list room api --- changelog.d/14537.bugfix | 2 +- synapse/storage/databases/main/room.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/changelog.d/14537.bugfix b/changelog.d/14537.bugfix index 150da85d4d93..d7ce78d0322a 100644 --- a/changelog.d/14537.bugfix +++ b/changelog.d/14537.bugfix @@ -1 +1 @@ -Fix a bug in the media admin room list API crashing when an image event exists with broken thumbnail information. Contributed by @schmop. \ No newline at end of file +Fix a long-standing bug where the [List media admin API](https://matrix-org.github.io/synapse/latest/admin_api/media_admin_api.html#list-all-media-in-a-room) would fail when processing an image with broken thumbnail information. \ No newline at end of file diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index 51ed9171239f..52ad947c6cfe 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -912,7 +912,11 @@ def _get_media_mxcs_in_room_txn( event_json = db_to_json(content_json) content = event_json["content"] content_url = content.get("url") - thumbnail_url = (content.get("info") or {}).get("thumbnail_url") + info = content.get("info") + if isinstance(info, dict): + thumbnail_url = info.get("thumbnail_url") + else: + thumbnail_url = None for url in (content_url, thumbnail_url): if not url: