bimg
bimg copied to clipboard
Crash when using trim
bimg panics when using certain combination of options. The following code works when changing Trim to false OR when changing Gravity to GravitySmart OR when switching Crop to true, but not with the combination of options below.
package main
import (
"fmt"
"os"
"github.com/h2non/bimg"
)
func main() {
options := bimg.Options{
Width: 142,
Height: 120,
Crop: false,
Quality: 85,
Interlace: true,
Gravity: bimg.GravityCentre,
Enlarge: true,
Trim: true,
Type: bimg.JPEG,
StripMetadata: true,
}
buffer, err := bimg.Read("6512736.jpeg")
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
newImage, err := bimg.NewImage(buffer).Process(options)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bimg.Write("out.jpg", newImage)
}
(bimg:18962): GLib-GObject-WARNING **: value "0" of type 'gint' is invalid or out of range for property 'width' of type 'gint'
(bimg:18962): GLib-GObject-WARNING **: value "0" of type 'gint' is invalid or out of range for property 'height' of type 'gint'
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7f042258c4b1]
runtime stack:
runtime.throw(0x5121f8, 0x2a)
/home/paso/.gvm/gos/go1.9/src/runtime/panic.go:605 +0x95
runtime.sigpanic()
/home/paso/.gvm/gos/go1.9/src/runtime/signal_unix.go:351 +0x2b8
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4ce640, 0xc420056df8, 0x7aa000)
/home/paso/.gvm/gos/go1.9/src/runtime/cgocall.go:132 +0xe4 fp=0xc420056dc8 sp=0xc420056d88 pc=0x405a24
github.com/bimg-crashtest/vendor/github.com/h2non/bimg._Cfunc_vips_colourspace_issupported_bridge(0x0, 0x0)
github.com/bimg-crashtest/vendor/github.com/h2non/bimg/_obj/_cgo_gotypes.go:493 +0x49 fp=0xc420056df8 sp=0xc420056dc8 pc=0x4c0069
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.vipsColourspaceIsSupported.func1(0x0, 0xc42000e060)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/vips.go:328 +0x60 fp=0xc420056e30 sp=0xc420056df8 pc=0x4c9060
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.vipsColourspaceIsSupported(0x0, 0xc42000e060)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/vips.go:328 +0x2b fp=0xc420056e50 sp=0xc420056e30 pc=0x4c615b
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.vipsPreSave(0x0, 0xc420056f60, 0x0, 0x0, 0x0)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/vips.go:380 +0x92 fp=0xc420056eb0 sp=0xc420056e50 pc=0x4c6382
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.vipsSave(0x0, 0x55, 0x6, 0x1, 0x10001, 0x0, 0x0, 0x16, 0x0, 0x0, ...)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/vips.go:407 +0xb6 fp=0xc420056f58 sp=0xc420056eb0 pc=0x4c66b6
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.saveImage(0x0, 0x78, 0x8e, 0x0, 0x0, 0x0, 0x0, 0x55, 0x6, 0x0, ...)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/resizer.go:170 +0x116 fp=0xc420057008 sp=0xc420056f58 pc=0x4c3456
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.resizer(0xc4200a0000, 0x228a8, 0x22aa8, 0x78, 0x8e, 0x0, 0x0, 0x0, 0x0, 0x55, ...)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/resizer.go:126 +0x6de fp=0xc4200578a8 sp=0xc420057008 pc=0x4c29ce
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.Resize(0xc4200a0000, 0x228a8, 0x22aa8, 0x78, 0x8e, 0x0, 0x0, 0x0, 0x0, 0x55, ...)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/resize.go:15 +0x12f fp=0xc420057a68 sp=0xc4200578a8 pc=0x4bf14f
github.com/bimg-crashtest/vendor/github.com/h2non/bimg.(*Image).Process(0xc420057e00, 0x78, 0x8e, 0x0, 0x0, 0x0, 0x0, 0x55, 0x0, 0x0, ...)
/go/src/github.com/bimg-crashtest/vendor/github.com/h2non/bimg/image.go:192 +0x85 fp=0xc420057c28 sp=0xc420057a68 pc=0x4beef5
main.main()
/go/src/github.com/bimg-crashtest/crashtest.go:29 +0x1a1 fp=0xc420057f80 sp=0xc420057c28 pc=0x4cd321
runtime.main()
/home/paso/.gvm/gos/go1.9/src/runtime/proc.go:185 +0x20d fp=0xc420057fe0 sp=0xc420057f80 pc=0x42d8bd
runtime.goexit()
/home/paso/.gvm/gos/go1.9/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420057fe8 sp=0xc420057fe0 pc=0x456861
exit status 2
Having the same problem with 8.4.5-1+b1
from debian stretch.
here is the code
package main
import (
"fmt"
bimg "gopkg.in/h2non/bimg.v1"
)
func main() {
buff, err := bimg.Read("./fuckfuck.jpg")
fmt.Println(err)
meta, err := bimg.Metadata(buff)
fmt.Println(meta.Alpha)
newIMG := bimg.NewImage(buff)
options := bimg.Options{Type: bimg.JPEG, Trim: true}
// keep the transparent background color
buff, err = newIMG.Process(options)
fmt.Println(err, len(buff))
bimg.Write("./fuck.jpg", buff)
}
it worked on my mac, but failed on debian debian output:
========== End Flags ===========
I12/25 07:13:56.850511 basic/entry.go:11] Starting server. Sentry ping check.
I12/25 07:13:56.850734 gaia/main.go:26] HTTP server ready to serve on 80
(bimg:1): GLib-GObject-CRITICAL **: g_value_type_compatible: assertion 'G_TYPE_IS_VALUE (src_type)' failed
(bimg:1): GLib-GObject-WARNING **: value "0" of type 'gint' is invalid or out of range for property 'width' of type 'gint'
(bimg:1): GLib-GObject-WARNING **: value "0" of type 'gint' is invalid or out of range for property 'height' of type 'gint'
(bimg:1): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7f7f3dcb4111]
runtime stack:
runtime.throw(0xc9e626, 0x2a)
/usr/local/go/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:374 +0x2f2
goroutine 56 [syscall]:
runtime.cgocall(0xabcaf0, 0xc0005490d0, 0x0)
/usr/local/go/src/runtime/cgocall.go:128 +0x5e fp=0xc0005490a0 sp=0xc000549068 pc=0x4076be
gopkg.in/h2non/bimg%2ev1._Cfunc_vips_colourspace_issupported_bridge(0x0, 0x0)
_cgo_gotypes.go:604 +0x49 fp=0xc0005490d0 sp=0xc0005490a0 pc=0x904ea9
gopkg.in/h2non/bimg%2ev1.vipsColourspaceIsSupported.func1(0x0, 0xc00054c018)
/go/src/gopkg.in/h2non/bimg.v1/vips.go:324 +0x56 fp=0xc000549108 sp=0xc0005490d0 pc=0x90ddc6
gopkg.in/h2non/bimg%2ev1.vipsColourspaceIsSupported(0x0, 0xc00054c018)
/go/src/gopkg.in/h2non/bimg.v1/vips.go:324 +0x2b fp=0xc000549128 sp=0xc000549108 pc=0x90b02b
gopkg.in/h2non/bimg%2ev1.vipsPreSave(0x0, 0xc000549230, 0x0, 0x0, 0x0)
/go/src/gopkg.in/h2non/bimg.v1/vips.go:376 +0x86 fp=0xc000549178 sp=0xc000549128 pc=0x90b346
gopkg.in/h2non/bimg%2ev1.vipsSave(0x0, 0x50, 0x6, 0x2, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, ...)
/go/src/gopkg.in/h2non/bimg.v1/vips.go:402 +0x99 fp=0xc000549228 sp=0xc000549178 pc=0x90b599
gopkg.in/h2non/bimg%2ev1.saveImage(0x0, 0x14d, 0x1f4, 0x0, 0x0, 0x0, 0x0, 0x50, 0x6, 0x0, ...)
/go/src/gopkg.in/h2non/bimg.v1/resizer.go:169 +0x137 fp=0xc0005492d8 sp=0xc000549228 pc=0x9085d7
gopkg.in/h2non/bimg%2ev1.resizer(0xc000512000, 0xd38a, 0xfe00, 0x14d, 0x1f4, 0x0, 0x0, 0x0, 0x0, 0x50, ...)
/go/src/gopkg.in/h2non/bimg.v1/resizer.go:124 +0x572 fp=0xc000549a40 sp=0xc0005492d8 pc=0x907c32
gopkg.in/h2non/bimg%2ev1.Resize(0xc000512000, 0xd38a, 0xfe00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/go/src/gopkg.in/h2non/bimg.v1/resize.go:15 +0x105 fp=0xc000549c08 sp=0xc000549a40 pc=0x903f45
gopkg.in/h2non/bimg%2ev1.(*Image).Process(0xc000437ee0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/go/src/gopkg.in/h2non/bimg.v1/image.go:192 +0x78 fp=0xc000549db8 sp=0xc000549c08 pc=0x9039f8
buff, err = newIMG.Process(options)
This is very important for me too, same error. Tried a lot of different vips versions, same error. Ubuntu 18
I think the problem is defer C.g_object_unref(C.gpointer(image)).
case o.Trim:
// C.g_object_unref(C.gpointer(image))
left, top, width, height, err := vipsTrim(image, o.Background, o.Threshold)
if err == nil {
// C.g_object_unref(C.gpointer(image))
image, err = vipsExtract(image, left, top, width, height)
}
Try comment this line.
func vipsTrim(image *C.VipsImage, background Color, threshold float64) (int, int, int, int, error) {
//defer C.g_object_unref(C.gpointer(image))
top := C.int(0)
left := C.int(0)
width := C.int(0)
height := C.int(0)
err := C.vips_find_trim_bridge(image,
&top, &left, &width, &height,
C.double(background.R), C.double(background.G), C.double(background.B),
C.double(threshold))
if err != 0 {
return 0, 0, 0, 0, catchVipsError()
}
return int(top), int(left), int(width), int(height), nil
}