westonplatter / phashion

Ruby wrapper around pHash, the perceptual hash library for detecting duplicate multimedia files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to prevent bad image files from causing core dumps

kohder opened this issue · comments

commented

Getting core dumps whenever gem hits an image file that causes any kind of error. I've tried being defensive by checking all images with the FastImage gem beforehand but now crashing on an image that gets past the FastImage check.

Example:

Premature end of JPEG file
Premature end of JPEG file
convert.im6: JPEG datastream contains no image `/srv/app/pulp/public/uploads/tmp/1493639798-9541-0001-7668/pro_rbmf_15909214.jpg' @ error/jpeg.c/JPEGErrorHandler/316.
convert.im6: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3044.
sh: 1: gm: not found
terminate called after throwing an instance of 'cimg_library::CImgIOException'
  what():  [instance(0,0,0,0,(nil),non-shared)] CImg<unsigned char>::load() : Failed to recognize format of file '/srv/app/pulp/public/uploads/tmp/1493639798-9541-0001-7668/pro_rbmf_15909214.jpg'.
Aborted (core dumped)

How can I prevent the gem from crashing the Ruby process? A rescue block is not working in this case.

@kohder glad you got a working solution. I'd be happy to pull those changes in if you think it would make a nice enhancement.