diff --git a/config.sample.yaml b/config.sample.yaml index c5d4643ad743201f783a10def2409b8c1b03dade..7cfdd332fc2a3e699a90f53a196d5d6ade780a15 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -25,6 +25,9 @@ uploads: # The thumbnail configuration for the media repository. thumbnails: + # The maximum number of bytes an image can be before the thumbnailer refuses. + maxSourceBytes: 10485760 # 10MB default, 0 to disable + # All thumbnails are generated into one of the sizes listed here. The first size is used as # the default for when no width or height is requested. The media repository will return # either an exact match or the next largest size of thumbnail. diff --git a/src/github.com/turt2live/matrix-media-repo/config/config.go b/src/github.com/turt2live/matrix-media-repo/config/config.go index ff2416c44514b6356fe0178031f86aab534990ae..1a63932f72750b39856020eff013fbf5071fcb7a 100644 --- a/src/github.com/turt2live/matrix-media-repo/config/config.go +++ b/src/github.com/turt2live/matrix-media-repo/config/config.go @@ -24,6 +24,7 @@ type MediaRepoConfig struct { } `yaml:"uploads"` Thumbnails struct { + MaxSourceBytes int64 `yaml:"maxSourceBytes"` Sizes []struct { Width int `yaml:"width"` Height int `yaml:"height"` 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 7dc62fa4b72708073f50119256a1cc802a10f6e9..f000e8c7b20153bb0a96dd23ea937646b21bbb6b 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 @@ -66,6 +66,10 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, return thumb, err } + if media.SizeBytes > c.Thumbnails.MaxSourceBytes { + return thumb, errors.New("cannot thumbnail, image too large") + } + return generateThumbnail(ctx, media, targetWidth, targetHeight, method, c, db) }