After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 159550 - xmlNodeDump will never return
xmlNodeDump will never return
Status: VERIFIED FIXED
Product: libxml2
Classification: Platform
Component: general
2.6.11
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2004-11-26 12:03 UTC by Olivier Sirven
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A atom feed containing some invalid utf-8 strings (43.21 KB, text/plain)
2004-11-26 12:05 UTC, Olivier Sirven
Details

Description Olivier Sirven 2004-11-26 12:03:24 UTC
If the xmlNodePtr structure given to xmlNodeDump contains some invalid encoded
UTF-8 strings, xmlNodeDump will never return. xmlNodeDump should detect invalid
strings and quit in error to avoid infinite recursion.
Comment 1 Olivier Sirven 2004-11-26 12:05:19 UTC
Created attachment 34151 [details]
A atom feed containing some invalid utf-8 strings

Using the attached file to create a xmlNodePtr structure, just call the
function at the bottom and see what happends....infinite recursion :(

xmlChar *extractHTMLNode(xmlNodePtr cur, int children) {
    xmlBufferPtr    buf;
    xmlChar * result;

	printxmlNodeRecurse(cur, 0);
    buf = xmlBufferCreate();
    if (children) {
	while (cur != NULL) {
	    xmlNodeDump(buf, cur->doc, cur, 0, 0);
	    cur = cur->next;
	}
    } else {
	xmlNodeDump(buf, cur->doc, cur, 0, 0);
    }
    if (xmlBufferLength(buf) > 0) {
	result = xmlCharStrdup(xmlBufferContent(buf));
    }
    
    xmlBufferFree(buf);
    
    return (result);
}
Comment 2 William M. Brack 2004-11-26 15:45:25 UTC
1) your test routine has a questionable line of code "printxmlNodeRecurse(cur, 
0);" - I just removed it.
2) I'm not very clear on what you are expecting.  Your testfile begins with a 
processing instruction declaring that the encoding is in UTF-8 (which is not 
true).  There are many places within the parsing, etc. where checks are made 
to assure the input data is (internally) valid, i.e. UTF-8.  Apparently you 
are bypassing these checks (using XML_PARSE_RECOVER ??), thereby allowing 
invalid text data into the tree.  Then, you attempt to output this invalid 
data, and are surprised when there is a problem.
3) notwithstanding (2), I have put in an additional test which (should) 
prevent the "dead loop" which you experienced (it was not "infinite 
recursion", as that would have eventually terminated when stack space was 
exhausted). This change is in CVS (xmlIO.c).

Although this should work, I strongly suggest you should re-think your 
approach to working with data which is known to be invalid.
Comment 3 Daniel Veillard 2005-01-17 22:52:09 UTC
 This should be closed by release of libxml2-2.6.17,

   thanks,

Daniel