-
-
Notifications
You must be signed in to change notification settings - Fork 905
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
xpath //namespace::* returns garbage -> can lead to segfault #1155
Comments
Forgot another fun thing:
If you do the xpath twice, the binary garbage is gone and it works correctly. (the number 6464 is correct because it does it for all nodes and attributes). |
I was able to reproduce this in an irb session and a standalone program, but putting the code in the test suite it didn't cause SEGV. There could be some kind of a problem with initialization. |
I guess this is caused by an unguarded VALUE swept by GC. It will take some time to investigate... |
Looking into this now. On Thu, Nov 6, 2014 at 6:57 PM, Akinori MUSHA [email protected]
|
I can see the memory error introduced by this code by running |
OK, I guess the good news is that this bug appears to have been present as long ago as June 2012 (v1.5.3), and this is the first time someone's noticed. The bad news is that this bug appears to have been present as long ago as June 2012, and this is the first time someone's noticed. Given this fact, I'm not going to try to rush a fix into 1.6.4.1. Give me some time (when I'm back from vacation next week) to dig in and try to figure out what's going on, and carefully try to fix it. |
(I forgot to mention, that I suspect this bug has been around since the dawn of time. I just got tired of building old versions of Nokogiri once I got to two years ago.) |
I concur with @knu that this is likely to be an initialization problem. I have not been able to reproduce the valgrind errors when I run the code in the test suite alongside other tests (though I can if I run the single test). Even setting |
I've put the test case on a branch: |
Hey, travis for the win. Caught Ruby 2.0 crashing in this test: |
Looking at this today with @akshaysawant ... think we have a fix. |
There's some history here, which I'll relate. Originally @tenderlove committed dbda52b to try to plug a memory leak, but that was dereferencing possibly-invalid pointers during Then, @ender672 committed 2675a75 which, though it didn't leak memory, introduced the bug you're seeing, which is that we're accessing the namespace nodes returned from an XPath query after the NodeSet has been GCed and freed the underlying namespace structs. What I'd like to do is closer to what @tenderlove originally proposed, which is to wrap a If we do this, then I think we'll have no invalid memory access and no leaks, and we'll be able to remove not only the Comments welcome, I'll probably drop this on a branch today and target it for 1.6.8. |
to stop freeing the namespace nodes when the NodeSet is GCed. Related to #1155
to remove nokogiriNodeSetTuple which is no longer necessary Related to #1155
this commit introduces a bifurcation in how Namespace objects are managed; Namespace objects wrapped around xmlNs structs from an xpath query now have their own Ruby object lifecycle and are GCed independently from their original document. See comments in xml_node_set.c and xml_namespace.c for more details. Related to #1155
Please see PR #1362 for my proposed fix, which is clean in valgrind and does not leak memory related to namespace xpath queries. |
to stop freeing the namespace nodes when the NodeSet is GCed. Related to #1155
to remove nokogiriNodeSetTuple which is no longer necessary Related to #1155
this commit introduces a bifurcation in how Namespace objects are managed; Namespace objects wrapped around xmlNs structs from an xpath query now have their own Ruby object lifecycle and are GCed independently from their original document. See comments in xml_node_set.c and xml_namespace.c for more details. Related to #1155
to stop freeing the namespace nodes when the NodeSet is GCed. Related to #1155
to remove nokogiriNodeSetTuple which is no longer necessary Related to #1155
this commit introduces a bifurcation in how Namespace objects are managed; Namespace objects wrapped around xmlNs structs from an xpath query now have their own Ruby object lifecycle and are GCed independently from their original document. See comments in xml_node_set.c and xml_namespace.c for more details. Related to #1155
PR merged onto master, will be fixed in 1.6.8. |
Execute the following code for the file http://gruppe.wst.univie.ac.at/~mangler/SimTest.xml:
It tells that it finds 6464 namespaces. Most of them are binary garbage. i.e.
Accessing them leads to segfaults. The first couple of namespaces are correct, but then (i suppose) it progresses into uncharted memory territory :-)
Funnily it works correctly for some XML files with namespaces. Funnily it works for some XML files with namespaces sometimes (heisenbug). The XML http://gruppe.wst.univie.ac.at/~mangler/SimTest.xml is the first one that i found that consistently lets me reproduce the error.
The text was updated successfully, but these errors were encountered: