Closed athomason closed 6 years ago
Hi. this code :
`func merging(c *gin.Context) {
profiles := c.PostForm("profiles")
images := c.PostForm("image")
filename := c.PostForm("filename")
pro, err := os.Open(profiles)
im, err := os.Open(images)
if err != nil {
fmt.Println(err)
}
img1, _, err := image.Decode(pro)
img2, _, err := image.Decode(im)
if err != nil {
fmt.Println(err)
}
//resize
imgs1 := resize.Resize(192, 192, img1, resize.Lanczos3)
imgs2 := resize.Resize(25, 25, img2, resize.Lanczos3)`
This error is :
runtime error: invalid memory address or nil pointer dereference /usr/local/go/src/runtime/panic.go:458 (0x31773) gopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz)) /usr/local/go/src/runtime/panic.go:62 (0x302cd) panicmem: panic(memoryError) /usr/local/go/src/runtime/sigpanic_unix.go:24 (0x461a4) sigpanic: panicmem() /Users/emildmaulana/go/src/github.com/nfnt/resize/resize.go:82 (0x109d2a) Resize: scaleX, scaleY := calcFactors(width, height, float64(img.Bounds().Dx()), float64(img.Bounds().Dy())) /Users/emildmaulana/go/gocrud/main.go:442 (0x53e0) merging: imgs1 := resize.Resize(192, 192, img1, resize.Lanczos3)
Inputs having zero as both width and height were caught, but either one alone caused a panic. This adds a test showing the old failing behavior and adds a check for non-positive width/height. Since Resize doesn't have an error return value, the behavior in this case is to return the original image.
Fixes #52
This is the panic, which is uncatchable by client code since it happens in a new goroutine:
This happens because the indexing arithmetic in resizeGray and friends attempts to access index 0 of a slice with no pixel data.