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

Pillow raises IOError on thumbnail generation #3325

@bryab

Description

@bryab

Description

When attempting to upload an image to a room through the Riot Android app, a server error occurs which prevents the image from being uploaded. It appears Pillow is raising an IOError.

Steps to reproduce

  • On Android, attempt to "share" an image to Riot, and select a room.

I receive an infinitely repeating "Internal server error", and I must force-stop the Riot app to recover from it. Below is the server error.

synapse.http.server - 102 - ERROR - POST-36609 - Failed handle request via <function _async_render_POST at 0x7fd81b836938>: <SynapseRequest at 0x7fd8183d3320 method=POST uri=/_matrix/media/v1/upload?access_token=<redacted>&filename=15279022308169654444447737565.jpg clientproto=HTTP/1.0 site=8008>: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 653, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1442, in gotResult
    _inlineCallbacks(r, g, deferred)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/failure.py", line 422, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
--- <exception caught here> ---
  File "/usr/local/lib/python2.7/dist-packages/synapse/http/server.py", line 79, in wrapped_request_handler
    yield h(self, request)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/failure.py", line 422, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/upload_resource.py", line 97, in _async_render_POST
    content_length, requester.user
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/failure.py", line 422, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/media_repository.py", line 164, in create_content
    None, media_id, media_id, media_type,
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/failure.py", line 422, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/media_repository.py", line 616, in _generate_thumbnails
    t_width, t_height, t_type,
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/threadpool.py", line 266, in <lambda>
    inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.7/dist-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/thumbnailer.py", line 60, in scale
    return self._encode_image(scaled, output_type)
  File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/thumbnailer.py", line 96, in _encode_image
    output_image.save(output_bytes_io, self.FORMATS[output_type], quality=80)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1935, in save
    save_handler(self, fp, filename)
  File "/usr/local/lib/python2.7/dist-packages/PIL/JpegImagePlugin.py", line 622, in _save
    raise IOError("cannot write mode %s as JPEG" % im.mode)
exceptions.IOError: cannot write mode RGBA as JPEG

Version information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions