ending \0 not included anymore in xmlReadMemory() input length?
Hello.
An issue was reported about a XML-related regression in our library hwloc (https://github.com/open-mpi/hwloc/issues/639) where libxml2 2.12 import fails with "parser error : Extra content at the end of the document".
It looks like somewhere between 2.9 and 2.12, xmlReadMemory() was changed to reject an input buffer whose length includes the ending \0. The following test case shows that a 6-char input <foo/>
is accepted with length 6 and 7 in libxml 2.9 but rejected with length 7 in libxml 2.12.1.
The new behavior doesn't feel crazy to me, but I couldn't find any documentation about the actual expectation from xmlReadMemory() input and length, hence I am asking:
Can you clarify to me and in the documentation whether the behavior change is expected and the given length parameter should never have included an optional ending \0 ?
Thanks
Brice
$ cat xml.c
#include <libxml/parser.h>
#include <assert.h>
int main() {
printf("xmlReadMemory without \\0...\n");
assert(xmlReadMemory("<foo/>", 6, "", NULL, XML_PARSE_NOBLANKS));
printf("xmlReadMemory with \\0...\n");
assert(xmlReadMemory("<foo/>", 7, "", NULL, XML_PARSE_NOBLANKS));
}
$ gcc -Wall xml.c -o xml -I/usr/include/libxml2/ -lxml2
$ ./xml
xmlReadMemory without \0...
xmlReadMemory with \0...
$ LD_LIBRARY_PATH=/path/to/libxml2-v2.12.1/install/lib ./xml
xmlReadMemory without \0...
xmlReadMemory with \0...
:1: parser error : Extra content at the end of the document
<foo/>
^
xml: xml.c:8: main: Assertion `xmlReadMemory("<foo/>", 7, "", NULL, XML_PARSE_NOBLANKS)' failed.
zsh: IOT instruction (core dumped) LD_LIBRARY_PATH=prout/libxml2-v2.12.1/install/lib ./xml