Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captchas not being generated in versions > 0.3.2. #50

Open
wpp opened this issue Feb 2, 2016 · 7 comments
Open

Captchas not being generated in versions > 0.3.2. #50

wpp opened this issue Feb 2, 2016 · 7 comments

Comments

@wpp
Copy link

wpp commented Feb 2, 2016

Hi there,

After a recent upgrade I noticed that captchas were not showing up:

screen shot 2016-02-02 at 11 04 22

I didn't see any errors in my server log, but my guess is that the tempfile changes generate_simple_captcha_image might be the problem?

Versions:

  • simple_captcha2 0.3.4
  • rails 4.2.1.5
  • ruby 2.2.4p230
  • ImageMagick 6.8.9-9 Q16 x86_64
  • Debian GNU/Linux 8.2 (jessie)

Version 0.4.0 had the same problem. Changing the simple_captcha2 version to 0.3.2 "fixed" the issue.

irb(main):001:0> include SimpleCaptcha::ImageHelpers
=> Object
irb(main):002:0> generate_simple_captcha_image('asdf')
  SimpleCaptcha::SimpleCaptchaData Load (1.4ms)  SELECT  `simple_captcha_data`.* FROM `simple_captcha_data` WHERE `simple_captcha_data`.`key` = 'asdf'  ORDER BY `simple_captcha_data`.`id` ASC LIMIT 1
-background '#fff' -fill '#000' -size 100x28 -wave 1x86 -gravity Center -pointsize 22 -implode 0.2 label: -evaluate Uniform-noise 0 jpeg:-
StandardError: Error while running convert: convert: no images defined `jpeg:-' @ error/convert.c/ConvertImageCommand/3210.

    from /usr/local/lib/ruby/gems/2.2.0/gems/simple_captcha2-0.3.4/lib/simple_captcha/utils.rb:17:in `run'
    from /usr/local/lib/ruby/gems/2.2.0/gems/simple_captcha2-0.3.4/lib/simple_captcha/image.rb:83:in `generate_simple_captcha_image'
    from (irb):2
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
@IanBurry
Copy link

I'm seeing the same problem

  • simple_captcha2 0.4.0
  • Rails 4.2.5.1
  • ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
  • ImageMagick 6.7.7-10 2014-03-06 Q16
  • Ubuntu 14.04.1 LTS

However, it's working just fine on my MacBook Pro

  • simple_captcha2 0.4.0
  • Rails 4.2.2
  • ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
  • ImageMagick 6.9.2-3 Q16 x86_64 2015-10-05
  • Mac OS X Yosemite v 10.10.5

@IanBurry
Copy link

IanBurry commented Apr 2, 2016

  • simple_captcha2 0.4.0

Looks like the problem is happening when SimpleCaptcha::Utils::run appends '2>&1' to the end of the convert command. Anything on STDERR gets redirected into STDOUT, and borks up the image data stream (if I understand this correctly). It also hides whatever was sent to STDERR.

Removing the redirection resulted in a valid captcha image and the error being displayed in the rails server console:

Fontconfig warning: ignoring C.UTF-8: not a valid language tag

in my case

@zealot128
Copy link
Member

hmm interesting, so that bug only happens if there are some encodings wrong, that's why I never ran into it.
I think we could just try to mute the errors in general "> /dev/null" instead. Best option would be using popen3 or similar to seperate the error and stdout stream.

@IanBurry
Copy link

@zealot128 I think it's simpler than that. Just let the errors go to stderr instead of redirecting them, then the OS can handle them. Alternately, make the redirection an option, so they can easily be muted.

@Melancholic
Copy link

Melancholic commented Mar 12, 2017

Hello!
Having understood the question, I came to the conclusion that this error was the result of the update of the ImageMagick policy. Link to the relevant news: https://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=29588.

The following solution helped me:

  1. vim /etc/ImageMagick/policy.xml
 50 <policymap>
 51   <!-- <policy domain="system" name="precision" value="6"/> -->
 52   <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
 53   <!-- <policy domain="resource" name="memory" value="2GiB"/> -->
 54   <!-- <policy domain="resource" name="map" value="4GiB"/> -->
 55   <!-- <policy domain="resource" name="area" value="1gb"/> -->
 56   <!-- <policy domain="resource" name="disk" value="16eb"/> -->
 57   <!-- <policy domain="resource" name="file" value="768"/> -->
 58   <!-- <policy domain="resource" name="thread" value="4"/> -->
 59   <!-- <policy domain="resource" name="throttle" value="0"/> -->
 60   <!-- <policy domain="resource" name="time" value="3600"/> -->
 61   <policy domain="coder" rights="none" pattern="EPHEMERAL" />
 62   <policy domain="coder" rights="none" pattern="HTTPS" />
 63   <policy domain="coder" rights="none" pattern="HTTP" />
 64   <policy domain="coder" rights="none" pattern="URL" />
 65   <policy domain="coder" rights="none" pattern="FTP" />
 66   <policy domain="coder" rights="none" pattern="MVG" />
 67   <policy domain="coder" rights="none" pattern="MSL" />
 68   <policy domain="coder" rights="none" pattern="TEXT" />
 69   <!--policy domain="coder" rights="none" pattern="LABEL" /-->         <!--comment this -->
 70   <policy domain="path" rights="none" pattern="@*" />
 71   <policy domain="coder" rights="read | write" pattern="JPEG" />       <!--add this -->
 72   <policy domain="coder" rights="read | write" pattern="PNG" />         <!--add this -->
 73 </policymap>

I'm not sure this solution is safe enough, but it works. If someone can tell how to improve security - I will be grateful. Maybe you need to update README. Thank you!

@jagdeepsingh
Copy link

Upgrading imagemagick to version 7.0.7-15 solved the issue for me.

@renji001
Copy link

delete '2>&1' worked for me !
imageMagick 6.7.8
fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants