element-hq / element-hq/synapse

Thumbnailer fails silently when a thumbnail of an encrypted image is requested

Open
#11,334 0 comments 0 reactions 0 assignees View on GitHub
A-Media-Repository P4 S-Tolerable T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#11334](https://github.com/matrix-org/synapse/issues/11334).

---

### Description

If I manually request a thumbnail of an image uploaded to an E2EE room (say, by sending `/html ` in Element) the server responds with

```json
{"errcode":"M_UNKNOWN","error":"Failed to generate thumbnail."}
```

With Python logging set to DEBUG, the server log prints:

```
2021-11-13 21:33:42,404 - synapse.rest.media.v1.thumbnail_resource - 167 - DEBUG - GET-682 - We don't have a thumbnail of that size. Generating
2021-11-13 21:33:42,404 - synapse.rest.media.v1.media_repository - 531 - WARNING - GET-682 - Unable to generate a thumbnail for local media [media_id] using a method of crop and type of image/png:
2021-11-13 21:33:42,404 - synapse.rest.media.v1.thumbnail_resource - 182 - WARNING - GET-682 - Failed to generate thumbnail
2021-11-13 21:33:42,404 - synapse.http.server - 88 - INFO - GET-682 - SynapseError: 400 - Failed to generate thumbnail.
```

I additionally added a line of logging at https://github.com/matrix-org/synapse/blob/605921bc6b3d3f48142e3c8b5ddcc6c2a0016062/synapse/rest/media/v1/thumbnailer.py#L50-L53
to print the text of the OSError exception; that line looks like this:

```
2021-11-13 21:33:42,404 - synapse.rest.media.v1.thumbnailer - 53 - INFO - GET-682 - Error opening image: cannot identify image file '/data/media_store/local_content/[media_id_directories_and_file]'
```

It seems like Pillow tries to open the encrypted image file, fails, and the Thumbnailer reports that the image couldn't be loaded.

It makes sense to me that thumbnailing an encrypted image might not be possible, but perhaps it would be appropriate to throw an error more indicative of what's going on?

### Steps to reproduce

- Upload an image to an E2EE room
- Copy its `mxc://` URL
- Send a message e.g. `![](mxc://homeserver.org/media_id)` or visit e.g. `https://homeserver.org/_matrix/media/r0/thumbnail/homeserver.org/media_id?width=32&height=32&method=crop`

### Version information

- **Homeserver**: Personal

If not matrix.org:

- **Version**: 1.42.0

- **Install method**: Git & Pip

- **Platform**: Docker (avhost/docker-matrix, Debian)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.