bakape / thumbnailer

Go media thumbnailer
MIT License
152 stars 36 forks source link

Exception in thumbnailer on windows #60

Closed matrosov-nikita closed 4 years ago

matrosov-nikita commented 4 years ago

I'm using MXE cross-compilation to build thumbnailer for windows OS. Got exception when call Thumbnail method.

Exception 0xc00000fd 0x1000 0x0 0x1004333
PC=0x1004333

runtime: unknown pc 0x1004333
stack: frame={sp:0x638fc14, fp:0x0} stack=[0x0,0x638fd90)
0638fb94:  0000001f  00000000  00000440  00000000 
0638fba4:  00000000  00000000  00000000  00000000 
0638fbb4:  00000000  00000000  c00000fd  00000000 
0638fbc4:  00000000  01004333  00000000  00001000 
0638fbd4:  00000000  7fa661d7  0638fc00  5b050130 
0638fbe4:  000002ff  0638fd28  004cd873  000002ff 
0638fbf4:  00000000  0638fd28  004cd873  002ff000 
0638fc04:  00000400  000002ff  00000001  0638fcc8 
0638fc14: <005fe010  000002ff  004cddf9  0638fcc8 
0638fc24:  0638fcc8  00000000  00fd2eca  00000000 
0638fc34:  3ff00000  00000001  00000400  000002ff 
0638fc44:  0638fc20  00000fe0  7fa91bc4  0638fc70 
0638fc54:  00000001  00000001  00002000  00000400 
0638fc64:  00286c40  000002ff  00000000  00000001 
0638fc74:  00264700  000002ff  00000000  00000000 
0638fc84:  3ff00000  027f0c7f  0109fd20  00264380 
runtime: unknown pc 0x1004333
stack: frame={sp:0x638fc14, fp:0x0} stack=[0x0,0x638fd90)
0638fb94:  0000001f  00000000  00000440  00000000 
0638fba4:  00000000  00000000  00000000  00000000 
0638fbb4:  00000000  00000000  c00000fd  00000000 
0638fbc4:  00000000  01004333  00000000  00001000 
0638fbd4:  00000000  7fa661d7  0638fc00  5b050130 
0638fbe4:  000002ff  0638fd28  004cd873  000002ff 
0638fbf4:  00000000  0638fd28  004cd873  002ff000 
0638fc04:  00000400  000002ff  00000001  0638fcc8 
0638fc14: <005fe010  000002ff  004cddf9  0638fcc8 
0638fc24:  0638fcc8  00000000  00fd2eca  00000000 
0638fc34:  3ff00000  00000001  00000400  000002ff 
0638fc44:  0638fc20  00000fe0  7fa91bc4  0638fc70 
0638fc54:  00000001  00000001  00002000  00000400 
0638fc64:  00286c40  000002ff  00000000  00000001 
0638fc74:  00264700  000002ff  00000000  00000000 
0638fc84:  3ff00000  027f0c7f  0109fd20  00264380 

goroutine 1 [syscall]:
github.com/bakape/thumbnailer/v2._Cfunc_generate_thumbnail(0x5b050130, 0x241600, 0x264380, 0x0, 0x400, 0x2ff, 0x0)
    _cgo_gotypes.go:1266 +0x3f
github.com/bakape/thumbnailer/v2.(*FFContext).Thumbnail.func2(0x5b050130, 0x5b050100, 0x0, 0x264380, 0x400, 0x2ff, 0x5b075ef7)
    /go/pkg/mod/github.com/bakape/thumbnailer/v2@v2.5.4/thumbnailer.go:30 +0x117
github.com/bakape/thumbnailer/v2.(*FFContext).Thumbnail(0x5b050100, 0x400, 0x2ff, 0x0, 0x0, 0x0, 0x0)
    /go/pkg/mod/github.com/bakape/thumbnailer/v2@v2.5.4/thumbnailer.go:30 +0xe6
main.main()
    /thumbtest/main.go:34 +0x27b
eax     0x401010
ebx     0x638fcc8
ecx     0x6191c20
edx     0x5fe000
edi     0x0
esi     0x2000
ebp     0x638fd28
esp     0x638fc14
eip     0x1004333
eflags  0x10202
cs      0x23
fs      0x6b
gs      0x63

I created test project to easily reproduce this issue: https://github.com/matrosov-nikita/thumbtest

Steps to reproduce: 1) git clone https://github.com/matrosov-nikita/thumbtest 2) make build-win - it produces thumbtest.exe 3) thumbtest.exe --image=<path_to_image>

By some reason, this issue occurs only with image size over ~70Kb

Let me know, if I need to provide more information. Thanks. @bakape

bakape commented 4 years ago

From what I can tell, it seems to be a linker issue (see unknown pc 0x1004333). It is logged here https://github.com/golang/go/blob/9ee6ba089dc9dd2402bccd9ed28b07140f76de15/src/runtime/traceback.go#L167 My guess is, that somehow, when go switches the PC register over to the C, side it ends up at an invalid address.

These issues are most probably related: https://github.com/golang/go/issues/30186 https://github.com/golang/go/issues/28541

Basically, this seems to be either a bug in the Go compiler or in the linker provided by MXE. Try switching the MXE version in use and filing a Go bug, if that fails. From personal experience, cross compilation is too much of a hassle and compiling inside a Windows VM has less problems.

matrosov-nikita commented 4 years ago

@bakape, thanks for your quick response.

Building MXE from source with build-2019-06-02 and build-2019-03-04 releases didn't help.

One thing I'm concerning about is build failure on this line For MXE_TARGET=i686-w64-mingw32.static, got error cannot use _Ctype_ulong(img.size) (type _Ctype_ulong) as type _Ctype_uint in field value For MXE_TARGET=x86_64-w64-mingw32.static, got error cannot use _Ctype_ulong(img.size) (type _Ctype_ulong) as type _Ctype_ulonglong in field value

The only way to solve this error I've found is to explicitly rewrite a type in the file before compilation: https://github.com/matrosov-nikita/thumbtest/blob/master/Dockerfile#L29 What do you make of it?

bakape commented 4 years ago

Building MXE from source with build-2019-06-02 and build-2019-03-04 releases didn't help.

I've worked my share with MXE. If things don't work out, I still suggest compiling in a Win10 VM. Unless it actually is a Go compiler bug.

One thing I'm concerning about is build failure on this line For MXE_TARGET=i686-w64-mingw32.static, got error cannot use _Ctype_ulong(img.size) (type _Ctype_ulong) as type _Ctype_uint in field value For MXE_TARGET=x86_64-w64-mingw32.static, got error cannot use _Ctype_ulong(img.size) (type _Ctype_ulong) as type _Ctype_ulonglong in field value

That's a bug. Should be fixed now.