From 89cd160d9f966916f9a3f8063896eb58296f331c Mon Sep 17 00:00:00 2001 From: Ron Mayer Date: Wed, 9 Jan 2019 16:46:58 -0800 Subject: [PATCH 1/2] allow large xml entity values --- src/backend/utils/adt/xml.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 1cec168b2a194..1c9982933b339 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -1422,6 +1422,10 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, xmlInitParser(); ctxt = xmlNewParserCtxt(); + + /* allow large XML entity values */ + ctxt->options |= XML_PARSE_HUGE; + if (ctxt == NULL || xmlerrcxt->err_occurred) xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY, "could not allocate parser context"); From ab6b440bcf5d44173b2f6af538dae09dd6a46029 Mon Sep 17 00:00:00 2001 From: Ron Mayer Date: Wed, 9 Jan 2019 18:58:57 -0800 Subject: [PATCH 2/2] provides the 'XML_PARSE_HUGE' context to libxml so we can store xml values with over 10mb entities --- src/backend/utils/adt/xml.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 1c9982933b339..4816dd6321e62 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -1422,15 +1422,22 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, xmlInitParser(); ctxt = xmlNewParserCtxt(); - - /* allow large XML entity values */ - ctxt->options |= XML_PARSE_HUGE; - if (ctxt == NULL || xmlerrcxt->err_occurred) xml_ereport(xmlerrcxt, ERROR, ERRCODE_OUT_OF_MEMORY, "could not allocate parser context"); - if (xmloption_arg == XMLOPTION_DOCUMENT) + /* + * allow large XML entity values. + * + * Note that the latter code path doesn't preserve + * the ctxt->options value; so force the first code + * path. Yes, this breaks empty documents. + * + * + */ + ctxt->options |= XML_PARSE_HUGE; + + if (true || (xmloption_arg == XMLOPTION_DOCUMENT)) { /* * Note, that here we try to apply DTD defaults @@ -1467,6 +1474,15 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace, doc->encoding = xmlStrdup((const xmlChar *) "UTF-8"); doc->standalone = standalone; + /* + * Attempt to allow large XML entity values. + * + * Hmm..... the docs imply this would work, but the parseFlag + * does not get copied to the xmlParserCtxtPtr created + * within xmlParseBalancedChunkMemory. :( + */ + doc->parseFlags = XML_PARSE_HUGE; + /* allow empty content */ if (*(utf8string + count)) {