GNOME Bugzilla – Bug 659361
xmlCopyProp copies incorrectly attribute namespace
Last modified: 2021-07-05 13:25:13 UTC
When doing xmlDocCopyNode() from one document to another, xmlCopyProp() incorrectly copies xml: attribute namespace ptr from one document to another document - this namespace seems to be freed when original document is destroyed, what results in random SIGSEGVs or garbled output by xmlNodeDump() on (second) document. Possible way to reproduce: 1. create document with xml:lang attrib on some node 2. create 2nd document 3. import node tree with xml:lang attrib 4. dump 2nd document This is my assumption what happens, it was pretty hard to discover where this bug comes from and there was no more time to describe it better ;) IMHO code responsible for this bug is in tree.c:3973 - maybe there should be also check if referenced namespace really belongs to current document. /* * we have to find something appropriate here since * we cant be sure, that the namespce we found is identified * by the prefix */ if (xmlStrEqual(ns->href, cur->ns->href)) { /* this is the nice case */ ret->ns = ns; } else { My (perl) app processes huge documents with many different namespaces, therefore it's interesting that this bug occurs only for xml: namespace (concretely xml:lang attrib), but this can depend on special handling of xml: namespace by libxml2. As a dummy fix for this I'm now cloning nodes, instead of importing them ;(
Note that libxslt also uses xmlDocCopyNode() API.
Tried to reproduce with the following Perl script: use strict; use XML::LibXML; my $source = XML::LibXML->new->parse_string(<<'EOF'); <elem> <child xml:lang="de"/> </elem> EOF my $dest = XML::LibXML->new->parse_string(<<'EOF'); <doc/> EOF my $copy = $dest->importNode($source->documentElement); $source = undef; # This should free the source document. $dest->documentElement->appendChild($copy); print $dest->toString; But works as expected. (importNode calls xmlDocCopyNode internally.)
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.