diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-12-11 14:19:32 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-12-11 14:19:32 +0000 |
commit | d80d505b1f70eae128990ce1a9517e5c5edead73 (patch) | |
tree | eeec77127889207fae0b44b5e95360cd953ee202 /synapse/media/v1 | |
parent | doc the thumbnail methods (diff) | |
download | synapse-d80d505b1f70eae128990ce1a9517e5c5edead73.tar.xz |
Limit the size of images that are thumbnailed serverside. Limit the size of file that a server will download from a remote server
Diffstat (limited to 'synapse/media/v1')
-rw-r--r-- | synapse/media/v1/base_resource.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/synapse/media/v1/base_resource.py b/synapse/media/v1/base_resource.py index 8c62ecd597..77b05c6548 100644 --- a/synapse/media/v1/base_resource.py +++ b/synapse/media/v1/base_resource.py @@ -43,6 +43,7 @@ class BaseMediaResource(Resource): self.server_name = hs.hostname self.store = hs.get_datastore() self.max_upload_size = hs.config.max_upload_size + self.max_image_pixels = hs.config.max_image_pixels self.filepaths = filepaths @staticmethod @@ -143,6 +144,7 @@ class BaseMediaResource(Resource): )) length, headers = yield self.client.get_file( server_name, request_path, output_stream=f, + max_size=self.max_upload_size, ) media_type = headers["Content-Type"][0] time_now_ms = self.clock.time_msec() @@ -226,6 +228,14 @@ class BaseMediaResource(Resource): thumbnailer = Thumbnailer(input_path) m_width = thumbnailer.width m_height = thumbnailer.height + + if m_width * m_height >= self.max_image_pixels: + logger.info( + "Image too large to thumbnail %r x %r > %r" + m_width, m_height, self.max_image_pixels + ) + return + scales = set() crops = set() for r_width, r_height, r_method, r_type in requirements: @@ -281,6 +291,14 @@ class BaseMediaResource(Resource): thumbnailer = Thumbnailer(input_path) m_width = thumbnailer.width m_height = thumbnailer.height + + if m_width * m_height >= self.max_image_pixels: + logger.info( + "Image too large to thumbnail %r x %r > %r" + m_width, m_height, self.max_image_pixels + ) + return + scales = set() crops = set() for r_width, r_height, r_method, r_type in requirements: |