ruby-vips icon indicating copy to clipboard operation
ruby-vips copied to clipboard

Occasional SIGABRT segfault

Open yhagio opened this issue 8 months ago • 3 comments

Describe the bug

I have seen several times following segfault error from Ruby on Rails app but not often like once a week, but quite not sure how it happens as I cannot reproduce it easily 😢. I use ruby-vips to generate gif image like

...
image = Vips::Image.black(width, height)
text_image = Vips::Image.text(text, dpi:, font:, fontfile:)
text_image = text_image.gravity(gravity, width, height)
text_image = text_image.ifthenelse(text_color_rgb, background_color_rgb, blend: true)
image = image.composite2(text_image, :over)
...
frames << image
...
gif_image = Vips::Image.arrayjoin(frames, across: 1)
gif_image.set_type(GObject::GINT_TYPE, 'page-height', frames.first.height)
gif_image.set_type(Vips::ARRAY_INT_TYPE, 'delay', Array.new(frames.length) { 1000 })
gif_image.write_to_buffer('.gif', effort: 1)

🐛 Only error log found (but no stacktrace from application code or gem 🤷🏼 )

Program terminated with signal SIGABRT, Aborted.
--
  | Download failed: Invalid argument.  Continuing without source file ./nptl/./nptl/pthread_kill.c.
  | #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
  |  
  | warning: 44	./nptl/pthread_kill.c: No such file or directory
  | [Current thread is 1 (Thread 0x78be58bfd6c0 (LWP 21896))]
  | #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
  | #1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
  | #2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
  | #3  0x000078beca63427e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
  | #4  0x000078beca6178ff in __GI_abort () at ./stdlib/abort.c:79
  | #5  0x000078be9d96cc04 in g_mutex_clear (mutex=<optimized out>) at ../../../glib/gthread-posix.c:1450
  | #6  g_mutex_clear (mutex=<optimized out>) at ../../../glib/gthread-posix.c:1445
  | #7  0x000078be9db6caf5 in vips_g_mutex_free () at /lib/x86_64-linux-gnu/libvips.so.42
  | #8  0x000078be9db9f70e in vips_semaphore_destroy () at /lib/x86_64-linux-gnu/libvips.so.42
  | #9  0x000078be9db76ed4 in ??? () at /lib/x86_64-linux-gnu/libvips.so.42
  | #10 0x000078be9db76a84 in ??? () at /lib/x86_64-linux-gnu/libvips.so.42
  | #11 0x000078be9d941c82 in g_thread_proxy (data=0x78be6219b320) at ../../../glib/gthread.c:835
  | #12 0x000078beca68baa4 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
  | #13 0x000078beca718c3c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

Any idea what's wrong? I guess it's coming from libvips, not ruby-vips gem but not sure 🙇🏼

Additional context

Environment

  • Ubuntu 24
  • ruby version: 3.4.2
  • ruby-vips version: 2.2.3

yhagio avatar Mar 25 '25 21:03 yhagio

Hello @yhagio,

How many frames are you combining? I suppose extremely large numbers might cause problems. Do you know which libvips version you are using?

You can make your code a little simpler. text now has an rgb option, so you can set the text and background colour directly:

image = Vips::Image.text('<span foreground="#xxxxxx" background="#xxxxxx">#{text}</span>')
image = image.gravity(gravity, width, height, extend: :copy)
frames << image

jcupitt avatar Mar 26 '25 10:03 jcupitt

FWIW, if you're using libvips 8.15.1 (the version provided by Ubuntu 24), please upgrade to the latest version to avoid issue https://github.com/libvips/libvips/issues/3835.

kleisauke avatar Mar 26 '25 11:03 kleisauke

Ah thank you both 🙏🏼 I'm using 8.15.1 I'll try upgrade 🙇🏼

yhagio avatar Mar 26 '25 12:03 yhagio