Thumbnailer fails with requested width=0
or height=0
#14579
Open
Description
This issue has been migrated from #14579.
Description
If you request a thumbnail with width=0&height=0
(for both scale
and crop
)
- container image returns
HTTP 500
- Ubuntu package returns the image
I cannot explain why the platforms behave differently.
In any case, validation of the rest API is missing (#13147).
Steps to reproduce
Ubuntu package deployment
- request an thumbnail image (eg. profile image)
HTTP GET
https://example.com/_matrix/media/r0/thumbnail/example.com/<media_id>?width=0&height=0&method=scale- you get the image
container deployment
- request an thumbnail image (eg. profile image)
HTTP GET
https://example.com/_matrix/media/r0/thumbnail/example.com/<media_id>?width=0&height=0&method=scale- you get an error
HTTP 500
:{"errcode":"M_UNKNOWN","error":"Internal server error"}
2022-11-29 09:40:59,762 - synapse.http.server - 124 - ERROR - GET-13- Failed handle request via 'ThumbnailResource': <XForwardedForRequest at 0x7f46681b7220 method='GET' uri='/_matrix/media/r0/thumbnail/k8s.azure.kird.net/qQlsITBVkgBeIrbvLpbByOOy?width=0&height=0&method=scale' clientproto='HTTP/1.1' site='8083'>
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 307, in _async_render_wrapper
callback_return = await self._async_render(request)
File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 337, in _async_render
callback_return = await raw_callback_return
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnail_resource.py", line 76, in _async_render_GET
await self._select_or_generate_local_thumbnail(
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnail_resource.py", line 178, in _select_or_generate_local_thumbnail
file_path = await self.media_repo.generate_local_exact_thumbnail(
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/media_repository.py", line 592, in generate_local_exact_thumbnail
t_byte_source = await defer_to_thread(-packages/synapse/rest/media/v1/thumbnail_resource.py", line 178, in _select_or_generate_local_thumbnail
file_path = await self.media_repo.generate_local_exact_thumbnail(
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/media_repository.py", line 592, in generate_local_exact_thumbnail
t_byte_source = await defer_to_thread(
File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 244, in inContext
result = inContext.theWork() # type: ignore[attr-de
File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 244, in inContext
result = inContext.theWork() # type: ignore[attr-defined]
File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 260, in <lambda>
inContext.theWork = lambda: context.call( # type: ignore[attr-defined]
File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 117, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 82, in callWithContext
return func(*args, **kw)
File "/usr/local/lib/python3.9/site-packages/synapse/logging/context.py", line 970, in g
return f(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/media_repository.py", line 562, in _generate_thumbnail
return thumbnailer.scale(t_width, t_height, t_type)
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnailer.py", line 143, in scale
with self._resize(width, height) as scaled:
File "/usr/local/lib/python3.9/site-packages/synapse/rest/media/v1/thumbnailer.py", line 135, in _resize
return self.image.resize((width, height), Image.ANTIALIAS)
File "/usr/local/lib/python3.9/site-packages/PIL/Image.py", line 2115, in resize
return self._new(self.im.resize(size, resample, box))
ValueError: height and width must be > 0
I am did the same image for both plattforms / servers.
Homeserver
another homeserver
Synapse Version
various
Installation Method
Other (please mention below)
Database
single PostgreSQL server
Workers
Multiple workers
Platform
- Container / K8s platform:
- Synapse v1.64.0 and 1.72.0 (
matrixdotorg/synapse:latest
)
- Synapse v1.64.0 and 1.72.0 (
- Debian/Ubuntu platform
- Synapse v1.71.0 (matrix.org package)
Configuration
No response
Relevant log output
see above
Anything else that would be useful to know?
container version:
cat /usr/local/lib/python3.9/site-packages/PIL/_version.py
# Master version for Pillow
__version__ = "9.3.0
package version:
cat /opt/venvs/matrix-synapse/lib/python3.8/site-packages/PIL/_version.py
# Master version for Pillow
__version__ = "9.2.0"