libxml-raku / LibXML-raku

Raku bindings to the libxml2 native library
Artistic License 2.0
11 stars 4 forks source link

Using DD function raises a SIGSEGV #87

Open demanuel opened 2 years ago

demanuel commented 2 years ago

Using dd on a LibXML::Document raises a SIGSEGV

Follow up of: https://github.com/rakudo/rakudo/issues/5052

Copying jonathanstowe analysis:

Trimming it somewhat to:

use LibXML;
use LibXML::Document;

sub MAIN(){
    my LibXML::Document $doc .=  parse: :string('<doc />');
    dd $doc;

}

Gives a back trace:

Thread 1 "rakudo-m" received signal SIGSEGV, Segmentation fault. 0x00007ffff788ec2f in get_attribute () from //usr/local/lib/libmoar.so Missing separate debuginfos, use: dnf debuginfo-install glibc-2.35-15.fc36.x86_64 libxml2-devel-2.9.14-1.fc36.x86_64 xz-libs-5.2.5-9.fc36.x86_64 zlib-1.2.11-32.fc36.x86_64 (gdb) bt full

0 0x00007ffff788ec2f in get_attribute () from //usr/local/lib/libmoar.so

No symbol table info available.

1 0x00007ffff7814494 in MVM_interp_run () from //usr/local/lib/libmoar.so

No symbol table info available.

2 0x00000000004015ef in main ()

No symbol table info available.

It would appear that the segfault is from trying to obtain the value of an attribute of the LibXML::Document object (it also will happen with say $doc.raku,) which would suggest that some otherwise unused attribute of the CStruct of LibXML::Document is defined with the incorrect size.

So it's likely that this is a problem with LibXML rather than rakudo.

dwarring commented 2 years ago

Works for me on Rakudo blead 2022.07-3-g9bc1beed7.

Update: Seeing some core dumps on repeated runs, may be flapping.

dwarring commented 2 years ago

As an extra check. both the following C and Raku code agree on an overall size of 176 for xmlDoc:

#include <libxml/tree.h>

int main(void) {
    printf("%ld\n", sizeof(xmlDoc));  # 176
}
use LibXML;
use LibXML::Document;
use NativeCall;

sub MAIN(){
    my LibXML::Document $doc .=  parse: :string('<doc />');
    say nativesizeof($doc.raw); # 176
    dd $doc;
}
dwarring commented 1 year ago

the raku method has been aliased in LibXML: 0.9..10 to work around [this problem in Spreadsheet::XLXS. The above example now completed with:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc/>\n"

A work-around rather than a fix.