shoes / shoes3

a tiny graphical app kit for ruby

Home Page:http://walkabout.mvmanila.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

crash (segfault) on macOS when loading invalid font file

apjanke opened this issue · comments

In Shoes 3.7 on macOS 10.14.5 (system ruby 2.3.7p456), when I call font() and its argument is not a valid font file, Shoes will segfault instead of raise an error. This happens when I try to load a directory or a plain text file as a font.

Here's a minimal repro. Run either of the *.rb files under Shoes to reproduce it.

shoes-font-segfault.zip

The stack trace for the crash looks like this in the "Problem Report for Shoes" dialog that pops up.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff731992c6 __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff73254bf1 pthread_kill + 284
2   libsystem_c.dylib             	0x00007fff731036a6 abort + 127
3   libruby.2.3.0.dylib           	0x0000000102ced179 die + 9
4   libruby.2.3.0.dylib           	0x0000000102ced39a rb_bug_context + 538
5   libruby.2.3.0.dylib           	0x0000000102dcc614 sigsegv + 68
6   libsystem_platform.dylib      	0x00007fff73249b5d _sigtramp + 29
7   ???                           	000000000000000000 0 + 0
8   libshoes.dylib                	0x00000001035685b2 shoes_load_font + 98
9   libshoes.dylib                	0x00000001035081f1 shoes_font + 97
10  libruby.2.3.0.dylib           	0x0000000102e546bb vm_call_cfunc + 299
11  libruby.2.3.0.dylib           	0x0000000102e3ddaf vm_exec_core + 10687
12  libruby.2.3.0.dylib           	0x0000000102e4eb65 vm_exec + 117
13  libruby.2.3.0.dylib           	0x0000000102e5cbcf eval_string_with_cref + 1407
14  libruby.2.3.0.dylib           	0x0000000102e4a8c1 rb_f_eval + 161
15  libruby.2.3.0.dylib           	0x0000000102e546bb vm_call_cfunc + 299
16  libruby.2.3.0.dylib           	0x0000000102e3ddaf vm_exec_core + 10687
17  libruby.2.3.0.dylib           	0x0000000102e4eb65 vm_exec + 117
18  libruby.2.3.0.dylib           	0x0000000102e4d672 vm_invoke_proc + 178
19  libruby.2.3.0.dylib           	0x0000000102e5b726 vm_call0_body + 1350
20  libruby.2.3.0.dylib           	0x0000000102e5be48 rb_call0 + 216
21  libshoes.dylib                	0x00000001035049ff shoes_safe_block_call + 191
22  libruby.2.3.0.dylib           	0x0000000102cf6ff5 rb_rescue2 + 277
23  libshoes.dylib                	0x000000010350491f shoes_safe_block + 111
24  libshoes.dylib                	0x00000001034fa4a9 shoes_canvas_send_click + 201
25  libshoes.dylib                	0x00000001034fa228 shoes_canvas_send_click2 + 760
26  libshoes.dylib                	0x00000001034fa41b shoes_canvas_send_click + 59
27  libshoes.dylib                	0x00000001034fa228 shoes_canvas_send_click2 + 760
28  libshoes.dylib                	0x00000001034fa41b shoes_canvas_send_click + 59
29  libshoes.dylib                	0x00000001034f3daf shoes_app_click + 527
30  libshoes.dylib                	0x00000001035660a7 -[ShoesWindow sendMotion:ofType:withButton:] + 743
31  libshoes.dylib                	0x0000000103566247 -[ShoesWindow mouseDown:] + 71
32  com.apple.AppKit              	0x00007fff449e6233 forwardMethod + 211
33  com.apple.AppKit              	0x00007fff449e6233 forwardMethod + 211
34  com.apple.AppKit              	0x00007fff449eab37 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5724
35  com.apple.AppKit              	0x00007fff449213a6 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2295
36  com.apple.AppKit              	0x00007fff44920867 -[NSWindow(NSEventRouting) sendEvent:] + 478
37  com.apple.AppKit              	0x00007fff447c004f -[NSApplication(NSEvent) sendEvent:] + 331
38  com.apple.AppKit              	0x00007fff447ae874 -[NSApplication run] + 755
39  libshoes.dylib                	0x000000010356a447 shoes_native_loop + 55
40  libshoes.dylib                	0x00000001034f227f shoes_app_loop + 63
41  libshoes.dylib                	0x00000001034f2232 shoes_app_start + 178
42  libshoes.dylib                	0x000000010351548d shoes_start + 1213
43  shoes-bin                     	0x0000000102c9dda2 main + 850
44  libdyld.dylib                 	0x00007fff7305e3d5 start + 1

Seems like this action should result in raising a normal Ruby exception instead of segfaulting.

Thanks for the bug report. This bug happened on Linux and Windows as well - different cures though. The betas for Shoes 3.3.8 now throw an exception.

I can confirm the fix. In 3.3.8 beta r3371, I now get this error when loading an invalid font file:

Error in <unknown> line 0 | 2019-05-27 17:57:05 -0400
Font "media/fonts/LICENSE.md" not found
/Users/janke/local/repos/peaksprints/lib/setup.rb:148:in `font'
/Users/janke/local/repos/peaksprints/lib/setup.rb:148:in `block in <top (required)>'
/Users/janke/local/repos/peaksprints/lib/setup.rb:146:in `each'
/Users/janke/local/repos/peaksprints/lib/setup.rb:146:in `<top (required)>'
/Applications/Shoes-3.3.8-beta-r3371.app/Contents/MacOS/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Applications/Shoes-3.3.8-beta-r3371.app/Contents/MacOS/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
opensprints.rb:127:in `<main>'
/Applications/Shoes-3.3.8-beta-r3371.app/Contents/MacOS/lib/shoes.rb:358:in `eval'
/Applications/Shoes-3.3.8-beta-r3371.app/Contents/MacOS/lib/shoes.rb:358:in `visit'
/Applications/Shoes-3.3.8-beta-r3371.app/Contents/MacOS/lib/shoes/setup.rb:100:in `block (2 levels) in setup_app'

Closing as fixed.