Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signal: segmentation fault #291

Open
Delicious-Bacon opened this issue Jul 16, 2022 · 15 comments
Open

signal: segmentation fault #291

Delicious-Bacon opened this issue Jul 16, 2022 · 15 comments

Comments

@Delicious-Bacon
Copy link

I had a Go project running around 250 concurrent image processing routines and had a crash with the only message being signal: segmentation fault.

I am running Ubuntu 22.04. on WSL2.

I have seen this note on memory. Can it be related to that? If so, how/where would I set the MALLOC_ARENA_MAX?

Something else that might be interesting is the ulimit -a output so I'll dump it here:

ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) 0
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 63824
max locked memory           (kbytes, -l) 65536
max memory size             (kbytes, -m) unlimited
open files                          (-n) 65535
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 63824
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited
@Delicious-Bacon
Copy link
Author

And another crash, but this time I got something more:

[signal SIGSEGV: segmentation violation code=0x1 addr=0x7fa0227d2fb1 pc=0x7fa817d36483]

runtime stack:
runtime.throw({0xf19108?, 0x7fa6fc084680?})
        /usr/local/go/src/runtime/panic.go:992 +0x71
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:802 +0x3a9

// long list of where the goroutines were during the panic...

@Delicious-Bacon
Copy link
Author

I forgot to add some lines of the trace that could be useful.

goroutine 23482 [syscall]:
runtime.cgocall(0xd1dd80, 0xc0001ecb48)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc0001ecb20 sp=0xc0001ecae8 pc=0x40b5bc
github.com/davidbyttow/govips/v2/vips._Cfunc_resize_image(0x7f19c80067e0, 0xc0000105b0, 0x3fe30f9525d7ee31, 0xbff0000000000000, 0x5)
        _cgo_gotypes.go:1774 +0x4c fp=0xc0001ecb48 sp=0xc0001ecb20 pc=0xc7e14c
github.com/davidbyttow/govips/v2/vips.vipsResizeWithVScale.func1(0xc0001ecbb0?, 0xc0001ecbd8?, 0x3fe30f9525d7ee31, 0xbff0000000000000, 0x5)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/resample.go:46 +0xa5 fp=0xc0001ecb98 sp=0xc0001ecb48 pc=0xc91485
github.com/davidbyttow/govips/v2/vips.vipsResizeWithVScale(0xc00001c640?, 0x8510?, 0x8511?, 0xffffffffffffffff)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/resample.go:46 +0xa5 fp=0xc0001ecc00 sp=0xc0001ecb98 pc=0xc91365
github.com/davidbyttow/govips/v2/vips.(*ImageRef).ResizeWithVScale(0xc00001c640, 0x3fe30f9525d7ee31, 0xbff0000000000000, 0xe3e?)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1521 +0x96 fp=0xc0001ecc48 sp=0xc0001ecc00 pc=0xc8eef6
github.com/davidbyttow/govips/v2/vips.(*ImageRef).Resize(...)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1508
github.com/Delicious-Bacon/ImgProject/actions/media.CreateImages({0xc004c044b0, 0x23}, {0xc0014f59b0, 0x16}, {0xc004c04480, 0x28}, {0xc0001ece80?, 0x2, 0x0?})

@Delicious-Bacon
Copy link
Author

Possibly related to:
flannel-io/flannel#1104
golang/go#30310
golang/go#13470
https://sourceware.org/bugzilla/show_bug.cgi?id=19341

But I am not sure I can do anything to resolve this myself if it's glibc links.

@bjg2
Copy link

bjg2 commented Aug 19, 2022

We're getting these as well, about ~1 per day. Any suggestion on how to mitigate this one? Should we maybe, for goroutines that trigger vips, use https://pkg.go.dev/runtime/debug#SetPanicOnFault (not sure that one would even do anything for cgo)?

Here are snippets from 3 crashes, I guess these routines are the ones that actually get SIGSEGV:

goroutine 1074617 [syscall]:
runtime.cgocall(0xcc9360, 0xc00064aff0)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc00064afc8 sp=0xc00064af90 pc=0x40b5fc
github.com/davidbyttow/govips/v2/vips._Cfunc_clear_image(0xc00013ae38)
        _cgo_gotypes.go:947 +0x45 fp=0xc00064aff0 sp=0xc00064afc8 pc=0xc66525
github.com/davidbyttow/govips/v2/vips.clearImage.func1(0xc00064b0a0?)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1792 +0x45 fp=0xc00064b028 sp=0xc00064aff0 pc=0xc7b9e5
github.com/davidbyttow/govips/v2/vips.clearImage(0x7fa768daa000)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1792 +0x5b fp=0xc00064b058 sp=0xc00064b028 pc=0xc7b97b
github.com/davidbyttow/govips/v2/vips.(*ImageRef).Close(0xc0007740a0)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:538 +0x65 fp=0xc00064b080 sp=0xc00064b058 pc=0xc76565

.....our stack here.....
goroutine 1948178 [syscall]:
runtime.cgocall(0xcc91d0, 0xc0014c4fd8)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc0014c4fb0 sp=0xc0014c4f78 pc=0x40b5fc
github.com/davidbyttow/govips/v2/vips._Cfunc_resize_image(0x7f8637979010, 0xc00071c4e8, 0x3fc7fb3428c4a579, 0x3fc8000000000000, 0x5)
        _cgo_gotypes.go:1772 +0x4c fp=0xc0014c4fd8 sp=0xc0014c4fb0 pc=0xc69a0c
github.com/davidbyttow/govips/v2/vips.vipsResizeWithVScale.func1(0xc0014c5040?, 0xc0014c5068?, 0x3fc7fb3428c4a579, 0x3fc8000000000000, 0x5)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/resample.go:46 +0xa5 fp=0xc0014c5028 sp=0xc0014c4fd8 pc=0xc7cac5
github.com/davidbyttow/govips/v2/vips.vipsResizeWithVScale(0xc002d55e50?, 0x0?, 0x0?, 0xffffffffffffffff)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/resample.go:46 +0xa5 fp=0xc0014c5090 sp=0xc0014c5028 pc=0xc7c9a5
github.com/davidbyttow/govips/v2/vips.(*ImageRef).ResizeWithVScale(0xc002d55e50, 0x3fc7fb3428c4a579, 0x3fc8000000000000, 0xc0014c5450?)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1521 +0x96 fp=0xc0014c50d8 sp=0xc0014c5090 pc=0xc7a536

.....our stack here.....
goroutine 662385 [syscall]:
runtime.cgocall(0xcc7b70, 0xc000f19058)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000f19030 sp=0xc000f18ff8 pc=0x40b5fc
github.com/davidbyttow/govips/v2/vips._Cfunc_average(0x7f7ad27a9190, 0xc00233d470)
        _cgo_gotypes.go:872 +0x4c fp=0xc000f19058 sp=0xc000f19030 pc=0xc6600c
github.com/davidbyttow/govips/v2/vips.vipsAverage.func1(0xc001d2b068?, 0xc000f19090?)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/arithmetic.go:84 +0x4c fp=0xc000f19098 sp=0xc000f19058 pc=0xc6c18c
github.com/davidbyttow/govips/v2/vips.vipsAverage(0xc001d2b040?)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/arithmetic.go:84 +0x6b fp=0xc000f190d8 sp=0xc000f19098 pc=0xc6c0eb
github.com/davidbyttow/govips/v2/vips.(*ImageRef).Average(...)
        /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1462

.....our stack here.....

@jishi92
Copy link
Contributor

jishi92 commented Sep 7, 2022

+1,by the way, vips._Cfunc_load_from_buffer also cause crash,when load_buffer("svgload_buffer", buf, len, params, set_svgload_options); it's inevitable.

@Delicious-Bacon
Copy link
Author

I have tested this on Linux CentOS 9 (Rocky Linux 9) and it happens there as well, so it's not WSL related.

Here's an example trace:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7fe6ee177f33 pc=0x7fe2494b84d3]

runtime stack:
runtime.throw({0xf72685?, 0x7fe249cc1ad0?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7fded15ef060 sp=0x7fded15ef030 pc=0x43da7d
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7fded15ef0b0 sp=0x7fded15ef060 pc=0x453769

goroutine 14660 [syscall]:
runtime.cgocall(0xd6c520, 0xc000bb1bd8)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc000bb1bb0 sp=0xc000bb1b78 pc=0x40b93c
github.com/davidbyttow/govips/v2/vips._Cfunc_clear_image(0xc024150188)
        _cgo_gotypes.go:963 +0x45 fp=0xc000bb1bd8 sp=0xc000bb1bb0 pc=0xcd9285
github.com/davidbyttow/govips/v2/vips.clearImage.func1(0x4?)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1792 +0x45 fp=0xc000bb1c10 sp=0xc000bb1bd8 pc=0xcee9c5
github.com/davidbyttow/govips/v2/vips.clearImage(0x7fe06c0d71a0)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:1792 +0x5b fp=0xc000bb1c40 sp=0xc000bb1c10 pc=0xcee95b
github.com/davidbyttow/govips/v2/vips.(*ImageRef).Close(0xc02382a4b0)
        /home/user/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:538 +0x65 fp=0xc000bb1c68 sp=0xc000bb1c40 pc=0xce9545

@mancabrera
Copy link

I am experiencing this exact same issue.

@bjg2 I tried a little snippet but it seems that SetPanicOnFault does not work with a C segementation fault. This is the explanation that I found: https://groups.google.com/g/golang-nuts/c/j4npkSTUZFs

My system is an Ubuntu in aws, so is not WSL related.

If anyone have found a workaround I would love to know.

Thanks!

@rektabhi
Copy link
Contributor

We are also facing similar issues, our application crashes about ~1 per day with SIGSEGV or SIGABRT, with different reasons. Errors are usually in the Composite, Export and Close methods.
Our application is running on Debian 11, so this is definitely not WSL/Ubuntu related.
Could it be related to #251?
Trimmed stack traces below:

double free or corruption (out)
SIGABRT: abort
PC=0x7faa41620ce1 m=28 sigcode=18446744073709551610
signal arrived during cgo execution
 
goroutine 4729779 [syscall]:
runtime.cgocall(0xdd5d10, 0xc000ff48f8)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc000ff48d0 sp=0xc000ff4898 pc=0x40c95c
***/govips-fork/v2/vips._Cfunc_composite_image(0xc000ef4100, 0xc0000de040, 0x5, 0xc000ea6030, 0xc000ea6040, 0xc000ea6050)
        _cgo_gotypes.go:1031 +0x4c fp=0xc000ff48f8 sp=0xc000ff48d0 pc=0x57e1ec
***/govips-fork/v2/vips.vipsComposite.func1(0x40?, 0xe42980?, {0xc000ea6030, 0xc?, 0x8?}, {0xc000ea6040, 0x10?, 0x4?}, {0xc000ea6050, 0x4, ...})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/conversion.go:401 +0x115 fp=0xc000ff4958 sp=0xc000ff48f8 pc=0x588c95
***/govips-fork/v2/vips.vipsComposite({0xc000ef4100, 0x5, 0x8}, {0xc000ea6030, 0x4, 0x4}, {0xc000ea6040, 0x4, 0x4}, {0xc000ea6050, ...})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/conversion.go:401 +0x108 fp=0xc000ff49d8 sp=0xc000ff4958 pc=0x588ac8
***/govips-fork/v2/vips.(*ImageRef).CompositeMulti(0xc0019f4e10, {0xc001c620a0, 0x4, 0x0?})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:1002 +0x45e fp=0xc000ff4af0 sp=0xc000ff49d8 pc=0x5937fe
free(): invalid pointer
SIGABRT: abort
PC=0x7f11fe73cce1 m=13 sigcode=18446744073709551610
signal arrived during cgo execution
 
goroutine 660236 [syscall]:
runtime.cgocall(0xdd5d10, 0xc00037c8f8)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc00037c8d0 sp=0xc00037c898 pc=0x40c95c
***/govips-fork/v2/vips._Cfunc_composite_image(0xc0008e2900, 0xc0018ae1a0, 0x5, 0xc000c7a800, 0xc000c7a810, 0xc000c7a820)
        _cgo_gotypes.go:1031 +0x4c fp=0xc00037c8f8 sp=0xc00037c8d0 pc=0x57e1ec
***/govips-fork/v2/vips.vipsComposite.func1(0x40?, 0xe42980?, {0xc000c7a800, 0xc?, 0x8?}, {0xc000c7a810, 0x10?, 0x4?}, {0xc000c7a820, 0x4, ...})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/conversion.go:401 +0x115 fp=0xc00037c958 sp=0xc00037c8f8 pc=0x588c95
***/govips-fork/v2/vips.vipsComposite({0xc0008e2900, 0x5, 0x8}, {0xc000c7a800, 0x4, 0x4}, {0xc000c7a810, 0x4, 0x4}, {0xc000c7a820, ...})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/conversion.go:401 +0x108 fp=0xc00037c9d8 sp=0xc00037c958 pc=0x588ac8
***/govips-fork/v2/vips.(*ImageRef).CompositeMulti(0xc0005fdc20, {0xc000243740, 0x4, 0x0?})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:1002 +0x45e fp=0xc00037caf0 sp=0xc00037c9d8 pc=0x5937fe
malloc_consolidate(): invalid chunk size
SIGABRT: abort
PC=0x7f1b753f6ce1 m=12 sigcode=18446744073709551610
signal arrived during cgo execution
 
goroutine 903458 [syscall]:
runtime.cgocall(0xdd66e0, 0xc000bcc590)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc000bcc568 sp=0xc000bcc530 pc=0x40c95c
***/govips-fork/v2/vips._Cfunc_save_to_buffer(0xc0010e0000)
        _cgo_gotypes.go:2042 +0x48 fp=0xc000bcc590 sp=0xc000bcc568 pc=0x582308
***/govips-fork/v2/vips.vipsSaveToBuffer.func1(0xc000bcc5e0?)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/foreign.go:464 +0x45 fp=0xc000bcc5c8 sp=0xc000bcc590 pc=0x58d0c5
***/govips-fork/v2/vips.vipsSaveToBuffer({0x7f1b00042010, 0x0, 0x1, 0x0, 0x0, 0x50, 0x1, 0x0, 0x0, 0x0, ...})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/foreign.go:464 +0xa5 fp=0xc000bcc640 sp=0xc000bcc5c8 pc=0x58ce85
***/govips-fork/v2/vips.vipsSaveJPEGToBuffer(0x7f1b00042010, {0x0, 0x50, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/foreign.go:350 +0x17b fp=0xc000bcc7d8 sp=0xc000bcc640 pc=0x58befb
***/govips-fork/v2/vips.(*ImageRef).ExportJpeg(0xc00175c000, 0x1000?)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:891 +0xa8 fp=0xc000bcc898 sp=0xc000bcc7d8 pc=0x592a68
***/govips-fork/v2/vips.(*ImageRef).ExportNative(0xc000bcca80?)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:881 +0x316 fp=0xc000bcca58 sp=0xc000bcc898 pc=0x592996
***/govips-fork/v2/vips.(*ImageRef).Export(0x0?, 0x0?)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:796 +0x4b6 fp=0xc000bccc00 sp=0xc000bcca58 pc=0x592636
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc pc=0x7f933d06168e]
 
runtime stack:
runtime.throw({0x106b7bd?, 0x5affcd1867b65500?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7f92f97f21c0 sp=0x7f92f97f2190 pc=0x44093d
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7f92f97f2210 sp=0x7f92f97f21c0 pc=0x457289
 
goroutine 5 [syscall]:
runtime.cgocall(0xdd6e60, 0xc00008ed30)
        /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc00008ed08 sp=0xc00008ecd0 pc=0x40c95c
***/govips-fork/v2/vips._Cfunc_clear_image(0xc000010178)
        _cgo_gotypes.go:1000 +0x45 fp=0xc00008ed30 sp=0xc00008ed08 pc=0x57e005
***/govips-fork/v2/vips.clearImage.func1(0xc0000ba820?)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:1923 +0x45 fp=0xc00008ed68 sp=0xc00008ed30 pc=0x5974c5
***/govips-fork/v2/vips.clearImage(0x7f9308286970)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:1923 +0x5b fp=0xc00008ed98 sp=0xc00008ed68 pc=0x59745b
***/govips-fork/v2/vips.(*ImageRef).Close(0xc0006aa050)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:576 +0x65 fp=0xc00008edc0 sp=0xc00008ed98 pc=0x591865
***/govips-fork/v2/vips.finalizeImage(0xc0006aa050)
        /go/pkg/mod/***/govips-fork/v2@v2.11.4/vips/image.go:566 +0x8d fp=0xc00008ee08 sp=0xc00008edc0 pc=0x5917cd

@bjg2
Copy link

bjg2 commented May 11, 2023

We mitigated by creating new processes that do vips stuff, and channeling data to them via stdin and from them via stdout. Very not cool but it works - if vips process crashes main process stays alive.

It would be much better if process would never crash, but I guess big part of engineering is getting the best out of the black box... :)

@rektabhi
Copy link
Contributor

@Delicious-Bacon The threads that you have shared state the issue in glibc when static binaries are used. I am not creating statically linked binary, could the failures still be due to the stated glibc bug?

@Delicious-Bacon
Copy link
Author

@Delicious-Bacon The threads that you have shared state the issue in glibc when static binaries are used. I am not creating statically linked binary, could the failures still be due to the stated glibc bug?

Not sure what do you mean by "statically linked binary" in your case.

As for my case, I ran my code via go run command, which doesn't generate a binary executable. It compiles and runs a program so I can't see how "when static binaries are used" refers to my issue then.

@rafaelsierra
Copy link
Contributor

I am also getting SIGSEGV after calling ResizeWithVScale:

fatal error: unexpected signal during runtime execution                                                                                                                  
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7f6556ebc1e3]                                                                                            
                                                                                                                                                                         
runtime stack:                                                                                                                                                           
runtime.throw({0x22da54d?, 0x7f6528e4c730?})                                                                                                                             
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7f652bdccc90 sp=0x7f652bdccc60 pc=0x440dbd                                                                    
runtime.sigpanic()                                                                                                                                                       
        /usr/local/go/src/runtime/signal_unix.go:825 +0x3e9 fp=0x7f652bdcccf0 sp=0x7f652bdccc90 pc=0x458349                                                              
                                                                                                                                                                         
goroutine 2933 [syscall]:                                                                                                                                                
runtime.cgocall(0x1cefe30, 0xc003ed5c68)                                                                                                                                 
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc003ed5c40 sp=0xc003ed5c08 pc=0x40be1c                                                                       
github.com/davidbyttow/govips/v2/vips._Cfunc_premultiply_alpha(0x7f65280b0910, 0xc001fde940)                                                                             
        _cgo_gotypes.go:1888 +0x4c fp=0xc003ed5c68 sp=0xc003ed5c40 pc=0xf00c4c                                                                                           
github.com/davidbyttow/govips/v2/vips.vipsPremultiplyAlpha.func1(0x0?, 0x0?)                                                                                             
        /go/pkg/mod/github.com/davidbyttow/govips/v2@v2.13.0/vips/conversion.go:366 +0x6f fp=0xc003ed5ca8 sp=0xc003ed5c68 pc=0xf0730f
github.com/davidbyttow/govips/v2/vips.vipsPremultiplyAlpha(0xc001fde928?)
        /go/pkg/mod/github.com/davidbyttow/govips/v2@v2.13.0/vips/conversion.go:366 +0x69 fp=0xc003ed5ce8 sp=0xc003ed5ca8 pc=0xf07249
github.com/davidbyttow/govips/v2/vips.(*ImageRef).PremultiplyAlpha(0xc0017f4500)
        /go/pkg/mod/github.com/davidbyttow/govips/v2@v2.13.0/vips/image.go:1157 +0x5a fp=0xc003ed5d18 sp=0xc003ed5ce8 pc=0xf125da
github.com/davidbyttow/govips/v2/vips.(*ImageRef).ResizeWithVScale(0xc0017f4500, 0x4070e00000000000, 0x4070e00000000000, 0x0?)
        /go/pkg/mod/github.com/davidbyttow/govips/v2@v2.13.0/vips/image.go:1647 +0x33 fp=0xc003ed5d60 sp=0xc003ed5d18 pc=0xf14353

I can't tell whether this is govips or libvips related

@rafaelsierra
Copy link
Contributor

I found out that the root of the problem was that some images had grayscale/b-w color space, and calling im.ToColorSpace(vips.InterpretationSRGB) before applying other operations solved the issue.

@cabrera-man
Copy link

Hello, @rafaelsierra
I'm having the exact same problem, could you provide an image that triggers this error? So I can replicate it in my local environment

@rafaelsierra
Copy link
Contributor

I finally had time to look deeper into the issue and (obviously) it's user error.

This is the minimum code I need to reproduce the sigsegv:

package main

import (
	"encoding/base64"
	"log"
	"os"

	"github.com/davidbyttow/govips/v2/vips"
)

// transparentPixelData contains a 1x1 webp transparent image
const transparentPixelData = `UklGRuoCAABXRUJQVlA4WAoAAAAwAAAAAAAAAAAASUNDUKACAAAAAAKgbGNtcwQwAABtbnRyUkdC
IFhZWiAH5wACABAACQAoADVhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAA
AADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1k
ZXNjAAABIAAAAEBjcHJ0AAABYAAAADZ3dHB0AAABmAAAABRjaGFkAAABrAAAACxyWFlaAAAB2AAA
ABRiWFlaAAAB7AAAABRnWFlaAAACAAAAABRyVFJDAAACFAAAACBnVFJDAAACFAAAACBiVFJDAAAC
FAAAACBjaHJtAAACNAAAACRkbW5kAAACWAAAACRkbWRkAAACfAAAACRtbHVjAAAAAAAAAAEAAAAM
ZW5VUwAAACQAAAAcAEcASQBNAFAAIABiAHUAaQBsAHQALQBpAG4AIABzAFIARwBCbWx1YwAAAAAA
AAABAAAADGVuVVMAAAAaAAAAHABQAHUAYgBsAGkAYwAgAEQAbwBtAGEAaQBuAABYWVogAAAAAAAA
9tYAAQAAAADTLXNmMzIAAAAAAAEMQgAABd7///MlAAAHkwAA/ZD///uh///9ogAAA9wAAMBuWFla
IAAAAAAAAG+gAAA49QAAA5BYWVogAAAAAAAAJJ8AAA+EAAC2xFhZWiAAAAAAAABilwAAt4cAABjZ
cGFyYQAAAAAAAwAAAAJmZgAA8qcAAA1ZAAAT0AAACltjaHJtAAAAAAADAAAAAKPXAABUfAAATM0A
AJmaAAAmZwAAD1xtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAEcASQBNAFBtbHVjAAAAAAAA
AAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJBTFBIAgAAAAAAVlA4IBoAAAAwAQCdASoBAAEAAAAA
JaQAA3AA/v/fbtQAAA==
`

func main() {
	ip := vips.NewImportParams()
	ip.FailOnError.Set(false)
	buff, _ := os.ReadFile("p.png")
	im, _ := vips.NewImageFromBuffer(buff)
	im.OptimizeICCProfile()
	im.Resize(2, vips.KernelLanczos3)

	b, _ := base64.StdEncoding.DecodeString(transparentPixelData)
	canvas, _ := vips.LoadImageFromBuffer(b, vips.NewImportParams())
	canvas.ResizeWithVScale(float64(im.Width()), float64(im.Height()), vips.KernelAuto)

	x := (canvas.Width() - im.Width()) / 2
	y := (canvas.Height() - im.Height()) / 2
	err := canvas.Composite(im, vips.BlendModeOver, x, y)
	if err != nil {
		log.Fatalf("failed to composite: %#v", err)
	}

	// Reduces the incoming image to 1x1 pixel
	err = im.Thumbnail(1, 1, vips.InterestingNone)
	if err != nil {
		log.Fatalf("failed to thumbnail: %#v", err)
	}

	// Adds an alpha channel to make sure we can draw a transparent square in the
	// entire image
	err = im.AddAlpha()
	if err != nil {
		log.Fatalf("failed to add alpha: %#v", err)
	}

	// Makes the image a single transparent pixel
	im.DrawRect(vips.ColorRGBA{A: 0}, 0, 0, 1, 1, true)

	// Scales image back to the size of the canvas
	// This will cause the application to crash
	im.ResizeWithVScale(float64(canvas.Width()), float64(canvas.Height()), vips.KernelAuto)

}

Where p.png is any PNG with black and white color mode which can be exported on Gimp by changing Image > Mode > Grayscale, make sure that the layer has alpha channel and then export as PNG with pixelformat 8bpc GRAYA

The issue is, of course, that im.DrawRect is returning an error that I am not checking, which causes internal pointers to become nil and when calling im.ResizeWithVScale it obviously crashes 🤦

If you are getting SIGSEGV, make sure that you are checking for errors every step of the way and stopping execution once an error happens.

I have a linter setup that is supposed to catch missing error checks but I guess it is not properly configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants