From 428eab36cdc0fe7a9e6d002700d75c291d1062b5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 26 Aug 2023 12:42:18 -0600 Subject: [PATCH] Apply max pixel count to blurhashes as well --- pipelines/_steps/upload/blurhash_async.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pipelines/_steps/upload/blurhash_async.go b/pipelines/_steps/upload/blurhash_async.go index d44a53c6..8cf54b0a 100644 --- a/pipelines/_steps/upload/blurhash_async.go +++ b/pipelines/_steps/upload/blurhash_async.go @@ -8,6 +8,7 @@ import ( "github.com/disintegration/imaging" "github.com/turt2live/matrix-media-repo/common/rcontext" "github.com/turt2live/matrix-media-repo/database" + "github.com/turt2live/matrix-media-repo/util/readers" ) func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeBytes int64, sha256hash string) chan struct{} { @@ -21,10 +22,24 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeB if !ctx.Config.Features.MSC2448Blurhash.Enabled { return } + + // Don't blurhash anything we wouldn't thumbnail if ctx.Config.Thumbnails.MaxSourceBytes <= sizeBytes { return } + // Same goes for pixel size + var c image.Config + br := readers.NewBufferReadsReader(reader) + c, _, err = image.DecodeConfig(br) + if err != nil { + return + } + if (c.Width * c.Height) >= ctx.Config.Thumbnails.MaxPixels { + return + } + reader = br.GetRewoundReader() + var img image.Image img, err = imaging.Decode(reader) if err != nil {