Skip to content

Commit b64a4e5

Browse files
reivilibresandhose
authored andcommitted
Restrict which image formats we will decode in order to generate thumbnails
1 parent 4b7154c commit b64a4e5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

synapse/media/thumbnailer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class ThumbnailError(Exception):
6767
class Thumbnailer:
6868
FORMATS = {"image/jpeg": "JPEG", "image/png": "PNG"}
6969

70+
# Which image formats we allow Pillow to open.
71+
# This should intentionally be kept restrictive, because the decoder of any
72+
# format in this list becomes part of our trusted computing base.
73+
PILLOW_FORMATS = ("jpeg", "png", "webp", "gif")
74+
7075
@staticmethod
7176
def set_limits(max_image_pixels: int) -> None:
7277
Image.MAX_IMAGE_PIXELS = max_image_pixels
@@ -76,7 +81,7 @@ def __init__(self, input_path: str):
7681
self._closed = False
7782

7883
try:
79-
self.image = Image.open(input_path)
84+
self.image = Image.open(input_path, formats=self.PILLOW_FORMATS)
8085
except OSError as e:
8186
# If an error occurs opening the image, a thumbnail won't be able to
8287
# be generated.

0 commit comments

Comments
 (0)