From 38745aed48dda027aa3a07b4b95ee3f37f6d6f8f Mon Sep 17 00:00:00 2001 From: Travis Ralston <travpc@gmail.com> Date: Sun, 12 Nov 2017 21:47:07 -0700 Subject: [PATCH] Cap maximum size to avoid really large thumbnails --- .../turt2live/matrix-media-repo/media_handler/thumbnailer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go b/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go index b6ffc8e4..7dc62fa4 100644 --- a/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go +++ b/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go @@ -31,6 +31,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, for i := 0; i < len(c.Thumbnails.Sizes); i++ { size := c.Thumbnails.Sizes[i] + lastSize := i == len(c.Thumbnails.Sizes) - 1 if width == size.Width && height == size.Height { targetWidth = width @@ -38,7 +39,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, break } - if size.Width < width || size.Height < height { + if (size.Width < width || size.Height < height) && !lastSize { continue // too small } @@ -50,7 +51,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, diff := diffWidth + diffHeight currDiff := currDiffWidth + currDiffHeight - if !foundFirst || diff < currDiff { + if !foundFirst || diff < currDiff || lastSize { foundFirst = true targetWidth = size.Width targetHeight = size.Height -- GitLab