tanoku/redcarpet — Issue #71: preprocess can cause segfault
Author: mchung
Created: 2011-11-23 01:41:58+00:00
State: open

If a custom renderer's preprocess method returns nil, the process segfaults

```
require 'test_helper'

class SampleRenderer < Redcarpet::Render::HTML
def preprocess(fulldoc)
nil
end
end

module ActiveBlog
class SampleRendererTest < ActiveSupport::TestCase
test "segfault" do
markdown = Redcarpet::Markdown.new(SampleRenderer)
puts markdown.render("This is *bongos*, indeed.")
end
end
end
```

Pukes out...

```
Loaded suite /Users/mchung/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
..../Users/mchung/Dropbox/workspace/active_blog/test/unit/active_blog/sample_renderer_test.rb:13: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.1]

-- control frame ----------
c:0019 p:---- s:0078 b:0078 l:000077 d:000077 CFUNC :render
c:0018 p:0041 s:0074 b:0073 l:0012f8 d:000072 LAMBDA /Users/mchung/Dropbox/workspace/active_blog/test/unit/active_blog/sample_renderer_test.rb:13
c:0017 p:---- s:0070 b:0070 l:000069 d:000069 FINISH
c:0016 p:0063 s:0068 b:0068 l:000910 d:000910 METHOD /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:695
c:0015 p:0010 s:0062 b:0062 l:002140 d:000061 BLOCK /Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:35
c:0014 p:0204 s:0060 b:0060 l:000059 d:000059 METHOD /Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:408
c:0013 p:0024 s:0051 b:0051 l:000050 d:000050 METHOD /Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81
c:0012 p:0021 s:0045 b:0045 l:002140 d:002140 METHOD /Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:34
c:0011 p:0091 s:0039 b:0039 l:000020 d:000038 BLOCK /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:656
c:0010 p:---- s:0034 b:0034 l:000033 d:000033 FINISH
c:0009 p:---- s:0032 b:0032 l:000031 d:000031 CFUNC :each
c:0008 p:0026 s:0029 b:0029 l:000020 d:000028 BLOCK /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:650
c:0007 p:---- s:0026 b:0026 l:000025 d:000025 FINISH
c:0006 p:---- s:0024 b:0024 l:000023 d:000023 CFUNC :each
c:0005 p:0082 s:0021 b:0021 l:000020 d:000020 METHOD /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:649
c:0004 p:0188 s:0016 b:0016 l:000015 d:000015 METHOD /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:609
c:0003 p:0057 s:0007 b:0007 l:000f98 d:000290 BLOCK /Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:508
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:002298 d:002298 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:508:in `block in autorun'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:609:in `run'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:649:in `run_test_suites'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:649:in `each'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:650:in `block in run_test_suites'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:650:in `each'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:656:in `block (2 levels) in run_test_suites'
/Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
/Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:408:in `_run_setup_callbacks'
/Users/mchung/.rvm/gems/ruby-1.9.2-p290@activeblog/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run'
/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/minitest/unit.rb:695:in `run'
/Users/mchung/Dropbox/workspace/active_blog/test/unit/active_blog/sample_renderer_test.rb:13:in `block in '
/Users/mchung/Dropbox/workspace/active_blog/test/unit/active_blog/sample_renderer_test.rb:13:in `render'

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

rake aborted!
Command failed with status (): [/Users/mchung/.rvm/rubies/ruby-1.9.2-p290/...]

Tasks: TOP => test
(See full trace by running task with --trace)
```