nfnt / resize

Pure golang image resizing
ISC License
3.02k stars 321 forks source link

"index out of range" panic from resizeRGBA64 #27

Closed teepark closed 9 years ago

teepark commented 9 years ago

In a goroutine spawned by the library no less, so it can't be recovered without patching it.

Here is the stack trace from the relevant goroutines:

panic: runtime error: index out of range

goroutine 34 [running]:
vendor/resize.resizeRGBA64(0xc20815e480, 0xc20815e140, 0x0, 0xc2080e7500, 0xc3c, 0xc3c, 0xc2080ef900, 0x30f, 0x30f, 0x4)
        /var/lib/gopath/src/git.pixinote.net/postman/vendor/resize/converter.go:152 +0x6b7
vendor/resize.func012()
        /var/lib/gopath/src/git.pixinote.net/postman/vendor/resize/resize.go:276 +0xce
created by vendor/resize.Resize
        /var/lib/gopath/src/git.pixinote.net/postman/vendor/resize/resize.go:277 +0x2a59

goroutine 31 [runnable]:
sync.(*WaitGroup).Wait(0xc2080d5c00)
        /usr/local/go/src/sync/waitgroup.go:132 +0x169
vendor/resize.Resize(0x30f, 0x30f, 0x7fcc97bda3d8, 0xc20815e440, 0x2, 0x0, 0x0)
        /var/lib/gopath/src/git.pixinote.net/postman/vendor/resize/resize.go:279 +0x2a98
endpoint.handleResize(0x8b25f0, 0x4, 0x15)
        /var/lib/gopath/src/git.pixinote.net/postman/endpoint/render.go:74 +0xa06
created by endpoint.putNoteImage
        /var/lib/gopath/src/git.pixinote.net/postman/endpoint/notes.go:668 +0x9fc
nfnt commented 9 years ago

I'm sorry, but without a sample program that can reproduce your issue, there is very little that I can do for you at the moment.

teepark commented 9 years ago

finally reproduced it consistently enough to debug, and I found that I was starting from an image with 0 height and 0 width, and trying to resize it up from there.

I was performing a crop with github.com/oliamb/cutter first, but a problem deserializing the crop dimensions caused me to chop it down to 0x0.

It might be worth it to check for this specific scenario, but the problem was certainly on my side.