add a new define XML_MAX_TEXT_LENGHT limiting the maximum size of a single
* include/libxml/parserInternals.h SAX2.c: add a new define
XML_MAX_TEXT_LENGHT limiting the maximum size of a single text
node, the defaultis 10MB and can be removed with the HUGE
parsing option
Daniel
svn path=/trunk/; revision=3808
diff --git a/ChangeLog b/ChangeLog
index affa9ba..5d40998 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Jan 18 15:06:05 CET 2009 Daniel Veillard <daniel@veillard.com>
+
+ * include/libxml/parserInternals.h SAX2.c: add a new define
+ XML_MAX_TEXT_LENGHT limiting the maximum size of a single text
+ node, the defaultis 10MB and can be removed with the HUGE
+ parsing option
+
Mon Jan 05 18:28:41 CET 2009 Rob Richards <rrichards@cdatazone.org>
* include/libxml/parser.h parser.c: add XML_PARSE_OLDSAX parser
diff --git a/SAX2.c b/SAX2.c
index 4b00ed6..d83a63c 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -2461,10 +2461,15 @@
(xmlDictOwns(ctxt->dict, lastChild->content))) {
lastChild->content = xmlStrdup(lastChild->content);
}
+ if (((size_t)ctxt->nodelen + (size_t)len > XML_MAX_TEXT_LENGHT) &&
+ ((ctxt->options & XML_PARSE_HUGE) == 0)) {
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters: huge text node");
+ return;
+ }
if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len ||
(size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) {
- xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
- return;
+ xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented");
+ return;
}
if (ctxt->nodelen + len >= ctxt->nodemem) {
xmlChar *newbuf;
diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h
index fddcd27..52113c5 100644
--- a/include/libxml/parserInternals.h
+++ b/include/libxml/parserInternals.h
@@ -24,18 +24,27 @@
/**
* xmlParserMaxDepth:
*
- * arbitrary depth limit for the XML documents that we allow to
- * process. This is not a limitation of the parser but a safety
- * boundary feature.
+ * arbitrary depth limit for the XML documents that we allow to
+ * process. This is not a limitation of the parser but a safety
+ * boundary feature, use XML_PARSE_HUGE option to override it.
*/
XMLPUBVAR unsigned int xmlParserMaxDepth;
- /**
- * XML_MAX_NAMELEN:
- *
- * Identifiers can be longer, but this will be more costly
- * at runtime.
- */
+/**
+ * XML_MAX_TEXT_LENGHT
+ *
+ * Maximum size allowed for a single text node when building a tree.
+ * This is not a limitation of the parser but a safety boundary feature,
+ * use XML_PARSE_HUGE option to override it.
+ */
+#define XML_MAX_TEXT_LENGHT 10000000
+
+/**
+ * XML_MAX_NAMELEN:
+ *
+ * Identifiers can be longer, but this will be more costly
+ * at runtime.
+ */
#define XML_MAX_NAMELEN 100
/**