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

Invalid memory access with libxml2 2.9.9 #7476

Closed
straight-shoota opened this issue Feb 22, 2019 · 3 comments
Closed

Invalid memory access with libxml2 2.9.9 #7476

straight-shoota opened this issue Feb 22, 2019 · 3 comments

Comments

@straight-shoota
Copy link
Member

The stdlib XML specs fail with the following error when linked against libxml2 2.9.9:

bin/crystal run --debug spec/std/xml/reader_spec.cr -- -e "#read_outer_xml"
Invalid memory access (signal 11) at address 0x40
[0xaab2f9c880e0] *CallStack::print_backtrace:Int32 +100
[0xaab2f969fb74] __crystal_sigfault_handler +228
[0xfff613bbe964] __setjmp +56
[0xfff613a33170] xmlTextReaderReadOuterXml +20
[0xaab2facf9dbc] *XML::Reader#read_outer_xml:String +24
[0xaab2f9c43b90] ~procProc(Nil) +44
[0xaab2f96c241c] *it<String, String, Int32, Int32, &Proc(Nil)>:(Array(Spec::Result) | Nil) +580
[0xaab2f9c43b54] ~procProc(Nil) +72
[0xaab2f9e1a3a0] *Spec::RootContext::describe<String, String, Int32, &Proc(Nil)>:Spec::Context+ +316
[0xaab2f96c7834] *describe<String, String, Int32, &Proc(Nil)>:Spec::Context+ +8
[0xaab2f9c3d420] ~procProc(Nil) +1024
[0xaab2f9e1a3a0] *Spec::RootContext::describe<String, String, Int32, &Proc(Nil)>:Spec::Context+ +316
[0xaab2f9c44644] *describe<XML::Reader.class, String, Int32, &Proc(Nil)>:Spec::Context+ +48
[0xaab2f968623c] __crystal_main +37812
[0xaab2fa6f3984] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +8
[0xaab2fa6f38dc] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +40
[0xaab2f968d624] main +8
[0xfff613b93734] ???
make: *** [Makefile:86: spec] Error 11
>>> ERROR: crystal: check failed

Tested on Alpine edge with Crystal 0.27.2

With 2.9.8. everything seems to work fine. LibXML2 changelog: https://gitlab.gnome.org/GNOME/libxml2/blob/a7fe7ee45938c53a8dd028dd40baa461191a2fd2/NEWS

This issue was first reported by mps on Gitter and I've been able to reproduce it.

@straight-shoota
Copy link
Member Author

The error also reproduces in a plain C implementation of the spec:

#include <stdio.h>
#include <libxml/xmlreader.h>

int main(int argc, char **argv) {
  xmlTextReaderPtr reader;

  reader = xmlReaderForMemory("<root>\n<child/>\n</root>\n", 23, NULL, NULL, 0);
  printf("%s", xmlTextReaderReadOuterXml(reader));
  xmlTextReaderRead(reader);
  printf("%s", xmlTextReaderReadOuterXml(reader));
}

So either we're using the API wrong or this is a libxml2 issue.

The only change to xmlTextReaderReadOuterXML between 2.9.8 and 2.9.9 was this one: https://gitlab.gnome.org/GNOME/libxml2/commit/39fbfb4fd08eae88d4b0c15f3a8ac33babc740e6

@straight-shoota
Copy link
Member Author

I filed an issue with libxml2: https://gitlab.gnome.org/GNOME/libxml2/issues/43

@asterite
Copy link
Member

It looks like a bug on their side.

However, on our side we can probably check the node type before invoking that C function. I think the outer XML is only available on some node types. I might give it a shot.

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

No branches or pull requests

2 participants