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

Segmentation fault at XmlXpathContext:evaluate (EXC_BAD_ACCESS) #159

Closed
poshaughnessy opened this issue Aug 28, 2012 · 5 comments · Fixed by #160
Closed

Segmentation fault at XmlXpathContext:evaluate (EXC_BAD_ACCESS) #159

poshaughnessy opened this issue Aug 28, 2012 · 5 comments · Fixed by #160

Comments

@poshaughnessy
Copy link

Hi,

Please could anyone help me out with this issue? (I'm a bit of a newbie).

I have a little Node script that makes some HTTP calls to grab some XML, parses it and generates some HTML from the results. It was working fine in Node v0.6. But since I upgraded to Node v0.8, it's failing with Segmentation Fault 11. (Clearing out the node_modules didn't help).

I installed Node from source and ran it using gdb. Here's the error I'm getting:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000100cd8f6e in libxmljs::XmlXpathContext::evaluate (this=<value temporarily unavailable, due to optimizations>, 
    xpath=<value temporarily unavailable, due to optimizations>) at xml_xpath_context.h:35
35  xml_xpath_context.h: No such file or directory.
    in xml_xpath_context.h
(gdb) backtrace
#0  0x0000000100cd8f6e in libxmljs::XmlXpathContext::evaluate (this=<value temporarily unavailable, due to optimizations>, 
    xpath=<value temporarily unavailable, due to optimizations>) at xml_xpath_context.h:35
#1  0x0000000100cd4cf6 in libxmljs::XmlElement::Find (args=<value temporarily unavailable, due to optimizations>) at ../src/xml_element.cc:170
#2  0x000000010017a662 in Builtin_Impl_HandleApiCall [inlined] () at ../deps/v8/src/builtins.cc:1145
#3  0x000000010017a662 in HandleApiCallHelper [inlined] () at :1161
#4  0x000000010017a662 in Builtin_HandleApiCall (args=
        {<v8::internal::Arguments> = {<v8::internal::Embedded> = {<No data fields>}, length_ = 4, arguments_ = 0x7fff5fbfe8b0}, <No data fields>}, 
    isolate=0x10101e200) at ../deps/v8/src/builtins.cc:1162
#5  0x0000373bbdd0618e in ?? ()
#6  0x0000373bbdddc5bd in ?? ()
#7  0x0000373bbdd098ee in ?? ()
#8  0x0000373bbdd8f08e in ?? ()
#9  0x0000373bbdd27fde in ?? ()
#10 0x0000373bbdd33f1f in ?? ()
#11 0x0000373bbdd098ee in ?? ()
#12 0x0000373bbddc4631 in ?? ()
#13 0x0000373bbddbdfeb in ?? ()
#14 0x0000373bbdd24ae7 in ?? ()
#15 0x0000373bbdd11477 in ?? ()
#16 0x00000001001c95e5 in Invoke (is_construct=<value temporarily unavailable, due to optimizations>, argc=0, args=0x0, 
    has_pending_exception=0x7fff5fbfec87) at ../deps/v8/src/execution.cc:118
#17 0x000000010013500c in v8::Function::Call (this=0x102001390, argc=0, argv=0x0) at ../deps/v8/src/api.cc:3644
#18 0x0000000100013bed in node::Parser::on_message_complete_ (this=0x101061e00) at ../src/node_http_parser.cc:333
#19 0x0000000100037fe4 in http_parser_execute (parser=0x101061e18, settings=0x10082af98, 
    data=0x1010dee00 "HTTP/1.1 200 OK\r\nServer: Apache-Coyote/1.1\r\nX-JAL: 2453\r\nContent-Type: text/xml;charset=UTF-8\r\nX-JSL: D=2453821 t=1346163674961319\r\nX-Cnection: close\r\nDate: Tue, 28 Aug 2012 14:16:57 GMT\r\nContent-Leng"..., len=2001) at ../deps/http_parser/http_parser.c:1565

The libxmljs method I'm using is parseXmlString.

Thanks in advance for any pointers or advice!

*Edit: Should have said, I'm on a Mac, v10.7.4 and I'm now running Node v0.8.8

@defunctzombie
Copy link
Collaborator

Can you provide a small XML sample and some js code that causes the segfault?

@poshaughnessy
Copy link
Author

Hi shtylman,

Sorry it turns out it didn't break because I upgraded Node. It broke because the XML I was downloading and parsing coincidentally changed during the same period.

Here's a simple script and data file that demonstrates the problem:

http://dl.dropbox.com/u/45897012/libxmljs/test.js
http://dl.dropbox.com/u/45897012/libxmljs/data.xml

It seems that the trouble is with the XPath. I'm trying to pull out a 'value' node within a 'return' node that doesn't exist.

...find('//return[fieldID=8]/value')

With this XML, there is no 'return' node with a fieldID of 8.

I can simply get around this by doing it in two steps. First, pulling out //return[fieldID=8] and then if I get a result back, looking inside it for value.

I was expecting that the find method would just silently return me an empty array or null back.

In the meantime I can easily rewrite it. But in case it happens for anyone else, it would be good if it didn't kill the app?

Thank you.

@polotek
Copy link
Collaborator

polotek commented Aug 29, 2012

I agree. It should probably be a little more graceful than a segfault :)

@jmandel
Copy link
Contributor

jmandel commented Aug 31, 2012

+1

Simple failing test (segfaults):

module.exports.get_missing = function(assert) {
    var doc = libxml.Document();
    var root = doc.node('root');

    var missing = doc.get('missing/text()');
    assert.equal(missing, undefined);
    assert.done();
};

@defunctzombie
Copy link
Collaborator

version 0.6.1 released which contains this patch, thank you for the contribution :)

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

Successfully merging a pull request may close this issue.

4 participants