element-hq / element-hq/element-ios

Element requests thumbnails in 0x0 pixel resolution

Open
#7,176 1 comment 0 reactions 0 assignees View on GitHub
O-Uncommon S-Tolerable T-Defect
Dominant language
Swift
Stars
1.8k
Forks
544
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

Being the homeserver operator, I can't tell you exactly what the user is doing, but I am pretty sure they are just using the client as intended.

### Outcome

#### What did you expect?
Normal operation

#### What happened instead?
I can see in the reverse proxy log that the Element client makes a request like the following:

`x.x.x.x - - [15/Dec/2022:09:34:16 +0100] "GET /_matrix/media/r0/thumbnail/matrix-server.example/rAgGyDiZgIGXzumIIYcQhWPB?width=0&height=0&method=scale HTTP/1.1" 500 5701 "-" "Element/1.9.13 (iPhone 14 Pro Max; iOS 16.2; Scale/3.00)"`

Notice the **width=0&height=0** part

This results in an error on the homeserver:

```
x/media/r0/thumbnail/matrix.gladblad.dk/rAgGyDiZgIGXzumIIYcQhWPB?width=0&height=0&method=scale' clientproto='HTTP/1.1' site='8008'>
Dec 15 09:34:16 matrix docker/synapse[1641]: Traceback (most recent call last):
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 307, in _async_render_wrapper
Dec 15 09:34:16 matrix docker/synapse[1641]: callback_return = await self._async_render(request)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 337, in _async_render
Dec 15 09:34:16 matrix docker/synapse[1641]: callback_return = await raw_callback_return
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnail_resource.py", line 76, in _async_render_GET
Dec 15 09:34:16 matrix docker/synapse[1641]: await self._select_or_generate_local_thumbnail(
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnail_resource.py", line 178, in _select_or_generate_local_thumbnail
Dec 15 09:34:16 matrix docker/synapse[1641]: file_path = await self.media_repo.generate_local_exact_thumbnail(
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/media_repository.py", line 592, in generate_local_exact_thumbnail
Dec 15 09:34:16 matrix docker/synapse[1641]: t_byte_source = await defer_to_thread(
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 244, in inContext
Dec 15 09:34:16 matrix docker/synapse[1641]: result = inContext.theWork() # type: ignore[attr-defined]
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 260, in
Dec 15 09:34:16 matrix docker/synapse[1641]: inContext.theWork = lambda: context.call( # type: ignore[attr-defined]
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 117, in callWithContext
Dec 15 09:34:16 matrix docker/synapse[1641]: return self.currentContext().callWithContext(ctx, func, *args, **kw)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 82, in callWithContext
Dec 15 09:34:16 matrix docker/synapse[1641]: return func(*args, **kw)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/logging/context.py", line 969, in g
Dec 15 09:34:16 matrix docker/synapse[1641]: return f(*args, **kwargs)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/media_repository.py", line 562, in _generate_thumbnail
Dec 15 09:34:16 matrix docker/synapse[1641]: return thumbnailer.scale(t_width, t_height, t_type)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnailer.py", line 143, in scale
Dec 15 09:34:16 matrix docker/synapse[1641]: with self._resize(width, height) as scaled:
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnailer.py", line 135, in _resize
Dec 15 09:34:16 matrix docker/synapse[1641]: return self.image.resize((width, height), Image.ANTIALIAS)
Dec 15 09:34:16 matrix docker/synapse[1641]: File "/usr/local/lib/python3.9/site-packages/PIL/Image.py", line 2115, in resize
Dec 15 09:34:16 matrix docker/synapse[1641]: return self._new(self.im.resize(size, resample, box))
Dec 15 09:34:16 matrix docker/synapse[1641]: ValueError: height and width must be > 0
```

Which again results in an error 500, and, what I suspect, is an empty image on the client.

Error is also reported in the Synapse project [here](https://github.com/matrix-org/synapse/issues/14579)

It would be nice if a check for 0x0 sized thumbnails could be made, and either fix the size or just not make requests if the size of the thumbnail is 0 in either width or height.

### Your phone model

iPhone 11, 12 and 14

### Operating system version

IOS 16, IOS 16.2

### Application version

Element 1.9.13

### Homeserver

Synapse 1.73.0

### Will you send logs?

Yes

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.