Skip to content

Commit

Permalink
Restrict which image formats we will decode in order to generate thum…
Browse files Browse the repository at this point in the history
…bnails
  • Loading branch information
reivilibre authored and sandhose committed Dec 3, 2024
1 parent 4b7154c commit b64a4e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion synapse/media/thumbnailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class ThumbnailError(Exception):
class Thumbnailer:
FORMATS = {"image/jpeg": "JPEG", "image/png": "PNG"}

# Which image formats we allow Pillow to open.
# This should intentionally be kept restrictive, because the decoder of any
# format in this list becomes part of our trusted computing base.
PILLOW_FORMATS = ("jpeg", "png", "webp", "gif")

@staticmethod
def set_limits(max_image_pixels: int) -> None:
Image.MAX_IMAGE_PIXELS = max_image_pixels
Expand All @@ -76,7 +81,7 @@ def __init__(self, input_path: str):
self._closed = False

try:
self.image = Image.open(input_path)
self.image = Image.open(input_path, formats=self.PILLOW_FORMATS)
except OSError as e:
# If an error occurs opening the image, a thumbnail won't be able to
# be generated.
Expand Down

0 comments on commit b64a4e5

Please sign in to comment.