From 39a43431167335b58a0c8b383dd317a5ba18ebbe Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 8 May 2022 23:05:05 +0900 Subject: [PATCH] internal/atlas: bug fix: wrong logic to create a new mask with edges * Fixed wrong operator orders * Cleared an allocated region explicitlly Closes #2089 --- internal/atlas/image.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/atlas/image.go b/internal/atlas/image.go index 2ff87f7de..33066440a 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -570,21 +570,25 @@ func (i *Image) replacePixels(pix []byte, mask []byte) { if mask != nil { origMask := mask mask = theTemporaryBytes.alloc((pw*ph-1)/8 + 1) + // Clear the allocated region explicitly (#2089). + for i := range mask { + mask[i] = 0 + } for i := 0; i < pw; i++ { // Top edge idx := i - mask[idx/8] |= 1 << idx % 8 + mask[idx/8] |= 1 << (idx % 8) // Bottom edge idx = (ph-1)*pw + i - mask[idx/8] |= 1 << idx % 8 + mask[idx/8] |= 1 << (idx % 8) } for j := 1; j < ph-1; j++ { // Left edge idx := j * pw - mask[idx/8] |= 1 << idx % 8 + mask[idx/8] |= 1 << (idx % 8) // Right edge idx = j*pw + pw - 1 - mask[idx/8] |= 1 << idx % 8 + mask[idx/8] |= 1 << (idx % 8) // Content for i := 1; i < pw-1; i++ {