From 987373420449df5bcf5f2241b5f78f04d1209e10 Mon Sep 17 00:00:00 2001 From: esimov Date: Tue, 9 Nov 2021 14:38:17 +0200 Subject: [PATCH] fix: limit max blur radius to 254 --- stackblur.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stackblur.go b/stackblur.go index 3923f6f..9aa4642 100644 --- a/stackblur.go +++ b/stackblur.go @@ -70,6 +70,15 @@ func StackBlur(img *image.NRGBA, radius uint32) *image.NRGBA { pr, pg, pb, pa uint32 ) + // Limit the maximum blur radius to 255, otherwise it overflows the multable length + // and will panic with and index out of range error. + if int(radius) >= len(mulTable) { + radius = uint32(len(mulTable) - 1) + } + if radius < 1 { + radius = 1 + } + div = radius + radius + 1 widthMinus1 = width - 1 heightMinus1 = height - 1