"I/O error : buffer full" printed from `xmlReadMemory` with specific input sizes (~multiples of 2)
Version: libxml2 2.10.3-2 (on Arch Linux)
When calling xmlReadMemory()
with data of exactly 8192
bytes, an error is printed: "I/O error : buffer full".
This also happens for inputs with length 16385
and 32771
(I expect for every input size following 8192 * 2^N + N
for any N >= 0
)
It does not happen if I increase/reduce the input size by any amount.
I tried to create a minimal example:
#include <libxml/parser.h>
#include <string.h>
#define INPUT_SIZE 8192
//#define INPUT_SIZE 16385
//#define INPUT_SIZE 32771
int main(int argc, char** argv)
{
const char* prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feed>\n";
const char* postfix = "</feed>\n";
char* input = malloc(INPUT_SIZE + 1);
const int start = strlen(prefix);
const int end = INPUT_SIZE - strlen(postfix);
strcpy(input, prefix);
for (int i = start; i < end; i++) {
input[i] = '.';
}
strcpy(input + end, postfix);
input[INPUT_SIZE] = 0;
xmlDocPtr doc = xmlReadMemory(input, INPUT_SIZE, "https://example.com/", NULL, 0);
if (doc != NULL) {
xmlNodePtr root = xmlDocGetRootElement(doc);
printf("root element: %s\n", root->name);
} else {
printf("parsing failed\n");
}
free(input);
return 0;
}
Output:
I/O error : buffer full
root element: feed
Originally reported on the Newsboat issue tracker: https://github.com/newsboat/newsboat/issues/2252