-
-
Notifications
You must be signed in to change notification settings - Fork 904
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
Segmentation fault inspecting some entities #1238
Comments
I dug into this a little bit, it appears the the I'm not sure exactly what's wrong with the entity declaration; but its In the meantime, try using |
Looking into this now, can still reproduce this segfault from commit 1691c0d
|
Valgrind says:
|
which is this line: VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
{
VALUE document = Qnil ;
VALUE node_cache = Qnil ;
VALUE rb_node = Qnil ;
nokogiriTuplePtr node_has_a_document;
xmlDocPtr doc;
void (*mark_method)(xmlNodePtr) = NULL ;
assert(node);
if(node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE)
return DOC_RUBY_OBJECT(node->doc);
/* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
/* see https://github.com/sparklemotion/nokogiri/issues/95 */
/* and https://github.com/sparklemotion/nokogiri/issues/439 */
doc = node->doc;
if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc; // THIS LINE HERE --------------------
node_has_a_document = DOC_RUBY_OBJECT_TEST(doc); |
Actually an even simpler repro (without a second document and the baggage that comes with that) is: #!/usr/bin/env ruby
require "nokogiri"
require "pp"
doc = Nokogiri::HTML('<p></p><div></div>')
ent = Nokogiri::XML::EntityReference.new(doc, "amp")
doc.at_css("div") << ent
STDERR.puts doc
pp doc which then crashes on this line: doc = node->doc;
if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc; // THIS LINE HERE ------------------
node_has_a_document = DOC_RUBY_OBJECT_TEST(doc); |
Notably, this only crashes when a predefined entity is being referenced. That is, is the entity is |
Updated: this is not related to reparenting, as this is enough to repro: #!/usr/bin/env ruby
require "nokogiri"
doc = Nokogiri::HTML('<div></div><div></div>')
ent1 = Nokogiri::XML::EntityReference.new(doc, "#xa")
ent2 = Nokogiri::XML::EntityReference.new(doc, "amp")
puts ent1.inspect
puts ent2.inspect we can inspect |
OK. So for predefined entities, libxml2 returns a node with a malformed child (see this code for the underlying implementation). To work around the segfault, I'll be committing a change that limits |
…-reparented-entities issue #1238 segfault on predefined entities
Will be in 1.8.2. |
libxml2 will cause EntityReferences to have a malformed child node for predefined entities. because any use of that child is likely to cause a segfault, we shall pretend that it doesn't exist. [fixes sparklemotion#1238]
Originally reported on the
nokogiri-talk
mailing list:I've rewritten the original example slightly:
running:
The text was updated successfully, but these errors were encountered: