Last active
August 29, 2015 14:26
-
-
Save codekitchen/2715ddc89e782b3e6c6f to your computer and use it in GitHub Desktop.
nokogiri + libxml memory corruption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This segfault was tested on Ubuntu Precise, With Ruby 2.1.6 and 2.2.2. | |
# It does _not_ crash on OS X Yosemite. | |
gem 'nokogiri', '1.6.6.2' | |
gem 'libxml-ruby', '2.8.0' | |
require 'nokogiri' | |
require 'libxml' # comment out this line, and no crash | |
message = "<h2>BOOM!</h2>" | |
20_000.times do | |
# GC.disable # disabling GC during the Nokogiri calls will prevent the crash | |
node = Nokogiri::HTML::DocumentFragment.parse(message) | |
node.add_previous_sibling(Nokogiri::XML::Text.new(' ', node.document)) | |
node.add_next_sibling(Nokogiri::XML::Text.new(' ', node.document)) | |
# GC.enable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment