Search code examples
ruby-on-rails-3rmagickcarrierwave

Carrierwave Rmagick Segmentation Fault on Wrong Photo Extension


I got a segmentation fault when I attempted to upload an image to my site on Heroku using Carrierwave with Rmagick.

This is part of the error log output:

ruby: jpc_dec.c:1072: jpc_dec_tiledecode: Assertion `dec->numcomps == 3' failed.
/app/.bundle/gems/ruby/1.9.1/gems/carrierwave-0.5.4/lib/carrierwave/processing/rmagick.rb:248: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

After investigation, the segmentation fault occurs because I attempted to upload a JPEG2000 file with a .jpg extension instead of the correct .jp2 extension.

Is this a bug with Rmagick?

More importantly, is it possible to prevent the users of my site from triggering this segmentation fault by sending an image with the wrong extension?

Thanks!


Solution

  • I doubt this will be its only error. You could use another tool, like 'file' to verify the file format.

    Also you should think about a way that makes it possible to recover if ruby crashes. You could just run an extra process in the background. But you should make sure that you have extra checks in place so that you can respond when someone tries to repeatedly crash your software. Otherwise you're an easy denial of service target.