disintegration / imaging

Imaging is a simple image processing package for Go
MIT License
5.22k stars 433 forks source link

Panic in the Rotate90 function. #159

Open hsnks100 opened 1 year ago

hsnks100 commented 1 year ago

The following code

package main

import (
    "image"

    "github.com/disintegration/imaging"
)

func Test() {
    yStride := 288
    cStride := 144
    width := 288
    height := 147

    im := &image.YCbCr{
        Y:              make([]uint8, yStride*height),
        Cb:             make([]uint8, (cStride*height)/2),
        Cr:             make([]uint8, (cStride*height)/2),
        YStride:        yStride,
        CStride:        yStride / 2,
        SubsampleRatio: image.YCbCrSubsampleRatio420,
        Rect: image.Rectangle{
            Min: image.Point{
                X: 0,
                Y: 0,
            },
            Max: image.Point{
                X: width,
                Y: height,
            },
        },
    }
    imaging.Rotate90(im)
}
func main() {
    Test()
}

result

go build && ./ip
panic: runtime error: index out of range [10654] with length 10584

goroutine 21 [running]:
github.com/disintegration/imaging.(*scanner).scan(0xc000116040, 0x11d, 0x0, 0x11e, 0x93, {0xc000180498, 0x0?, 0x290e8})
        /Users/diallo/go/pkg/mod/github.com/disintegration/imaging@v1.6.2/scanner.go:202 +0x8f0
github.com/disintegration/imaging.Rotate90.func1(0x0?)
        /Users/diallo/go/pkg/mod/github.com/disintegration/imaging@v1.6.2/transform.go:90 +0x6c
github.com/disintegration/imaging.parallel.func1()
        /Users/diallo/go/pkg/mod/github.com/disintegration/imaging@v1.6.2/utils.go:33 +0x63
created by github.com/disintegration/imaging.parallel
        /Users/diallo/go/pkg/mod/github.com/disintegration/imaging@v1.6.2/utils.go:31 +0xd6

There seems to be a problem when height is an odd number.