From 79a9938d843d38a64d7a17006cf5ad4335aa5b51 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 13 Dec 2023 17:25:37 +0100 Subject: [PATCH] parser: Don't grow or shrink pull parser memory buffers Readd check for memory buffers without a read callback to avoid XML_MAX_LOOKUP_LIMIT errors if users provide a custom input buffer. Regressed with commit 834b8123 and later changes. --- parserInternals.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/parserInternals.c b/parserInternals.c index 693cfd6d..241329cd 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -584,6 +584,9 @@ xmlParserGrow(xmlParserCtxtPtr ctxt) { /* Don't grow push parser buffer. */ if ((ctxt->progressive) && (ctxt->inputNr <= 1)) return(0); + /* Don't grow memory buffers. */ + if ((buf->encoder == NULL) && (buf->readcallback == NULL)) + return(0); if (buf->error != 0) return(-1); @@ -633,6 +636,10 @@ xmlParserInputGrow(xmlParserInputPtr in, int len) { if (in->cur == NULL) return(-1); if (in->buf->buffer == NULL) return(-1); + /* Don't grow memory buffers. */ + if ((in->buf->encoder == NULL) && (in->buf->readcallback == NULL)) + return(0); + indx = in->cur - in->base; if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) { return(0); @@ -666,6 +673,11 @@ xmlParserShrink(xmlParserCtxtPtr ctxt) { if (buf == NULL) return; + /* Don't shrink pull parser memory buffers. */ + if (((ctxt->progressive == 0) || (ctxt->inputNr > 1)) && + (buf->encoder == NULL) && + (buf->readcallback == NULL)) + return; used = in->cur - in->base; /*