anthonynsimon / bild

Image processing algorithms in pure Go
MIT License
3.97k stars 213 forks source link

[bug] runtime panic when rotating some images #78

Closed pyrox777 closed 4 years ago

pyrox777 commented 4 years ago

Hi there,

this issue might be related to #60 (coming back to this later). I'm running go1.13.7 linux/amd64 using go modules and wrote some example code (pyrox777/transform-example) to ease reproducibility. When rotating an image, represented in RGBA, with dimensions of 5535x3690 pixels (source) by 270° clockwise with ResizeBounds set to true, the panic is triggered. Here is the output:

~/.../pyrox777/transform-example >>> go run main.go ~/Downloads/erwan-hesry-IqB5MPcQp6k-unsplash.jpg /tmp/out.png
reading from /home/xxx/Downloads/erwan-hesry-IqB5MPcQp6k-unsplash.jpg
rotating image by 270.000000° clockwise
panic: runtime error: slice bounds out of range [:81696604] with capacity 81696600

goroutine 23 [running]:
github.com/anthonynsimon/bild/transform.Rotate.func1(0xd37, 0xe6a)
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/transform/rotate.go:111 +0x37d
github.com/anthonynsimon/bild/parallel.Line.func1(0xc000018110, 0xc000020240, 0xd37, 0xe6a)
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/parallel/parallel.go:33 +0x6a
created by github.com/anthonynsimon/bild/parallel.Line
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/parallel/parallel.go:31 +0x104
exit status 2

This is not the case when ResizeBounds is false, but I could not point out yet if this branch is the culprit.

Additionally, as started above, I was able to reproduce the panic with the image linked in #60:

~/.../pyrox777/transform-example >>> go run main.go ~/Downloads/41zcu25h98b0rquu.jpg /tmp/out.png
reading from /home/xxx/Downloads/41zcu25h98b0rquu.jpg
rotating image by 270.000000° clockwise
panic: runtime error: slice bounds out of range [:1223044] with capacity 1223040

goroutine 8 [running]:
github.com/anthonynsimon/bild/transform.Rotate.func1(0x1b8, 0x1e0)
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/transform/rotate.go:111 +0x37d
github.com/anthonynsimon/bild/parallel.Line.func1(0xc000018120, 0xc000020360, 0x1b8, 0x1e0)
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/parallel/parallel.go:33 +0x6a
created by github.com/anthonynsimon/bild/parallel.Line
        /home/xxx/go/pkg/mod/github.com/anthonynsimon/bild@v0.11.1/parallel/parallel.go:31 +0x104
exit status 2

So, thanks for this project and also having a look at this! :)

Edit: I have changed the title because the second image is not considered huge by me. But it has uneven dimensions as well (637x480). So maybe this could be a hint?

anthonynsimon commented 4 years ago

@pyrox777 thanks a lot for the detailed message, this is helpful! I will take a look into it.

pyrox777 commented 4 years ago

I can confirm that f0f3bd5 from #82 solves the problem. Thanks a lot, @harotobira!