diff -rup libxml2-2.9.4.ori/include/libxml/parser.h libxml2-2.9.4.new/include/libxml/parser.h
--- libxml2-2.9.4.ori/include/libxml/parser.h	2016-05-22 03:49:02.000000000 +0200
+++ libxml2-2.9.4.new/include/libxml/parser.h	2016-09-30 11:53:20.324891846 +0200
@@ -1111,7 +1111,8 @@ typedef enum {
     XML_PARSE_HUGE      = 1<<19,/* relax any hardcoded limit from the parser */
     XML_PARSE_OLDSAX    = 1<<20,/* parse using SAX2 interface before 2.7.0 */
     XML_PARSE_IGNORE_ENC= 1<<21,/* ignore internal document encoding hint */
-    XML_PARSE_BIG_LINES = 1<<22 /* Store big lines numbers in text PSVI field */
+    XML_PARSE_BIG_LINES = 1<<22,/* Store big lines numbers in text PSVI field */
+    XML_PARSE_CHECK_ENT = 1<<23 /* Always check non-linear entity expansion */
 } xmlParserOption;
 
 XMLPUBFUN void XMLCALL
diff -rup libxml2-2.9.4.ori/parser.c libxml2-2.9.4.new/parser.c
--- libxml2-2.9.4.ori/parser.c	2016-05-23 09:25:25.000000000 +0200
+++ libxml2-2.9.4.new/parser.c	2016-09-30 13:11:07.259298315 +0200
@@ -114,6 +114,13 @@ static void xmlHaltParser(xmlParserCtxtP
 #define XML_PARSER_NON_LINEAR 10
 
 /*
+ * XML_PARSER_HUGE_BUT_ENT is a shortcut for XML_PARSE_HUGE combined with
+ *    XML_PARSE_CHECK_ENT, one may still want to check for non-linear entity
+ *    expansion while allowing elements above XML_MAX_TEXT_LENGTH.
+ */
+#define XML_PARSER_HUGE_BUT_ENT (XML_PARSE_HUGE | XML_PARSE_CHECK_ENT)
+
+/*
  * xmlParserEntityCheck
  *
  * Function to check non-linear entity expansion behaviour
@@ -128,7 +135,8 @@ xmlParserEntityCheck(xmlParserCtxtPtr ct
 {
     size_t consumed = 0;
 
-    if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
+    if ((ctxt == NULL) ||
+        ((ctxt->options & XML_PARSER_HUGE_BUT_ENT) == XML_PARSE_HUGE))
         return (0);
     if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
         return (1);
@@ -2763,7 +2771,7 @@ xmlStringLenDecodeEntities(xmlParserCtxt
     last = str + len;
 
     if (((ctxt->depth > 40) &&
-         ((ctxt->options & XML_PARSE_HUGE) == 0)) ||
+         ((ctxt->options & XML_PARSER_HUGE_BUT_ENT) == 0)) ||
 	(ctxt->depth > 1024)) {
 	xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
 	return(NULL);
@@ -13120,7 +13128,8 @@ xmlParseCtxtExternalEntity(xmlParserCtxt
 
     if (ctx == NULL) return(-1);
 
-    if (((ctx->depth > 40) && ((ctx->options & XML_PARSE_HUGE) == 0)) ||
+    if (((ctx->depth > 40) &&
+         ((ctx->options & XML_PARSER_HUGE_BUT_ENT) == 0)) ||
         (ctx->depth > 1024)) {
 	return(XML_ERR_ENTITY_LOOP);
     }
@@ -13326,7 +13335,8 @@ xmlParseExternalEntityPrivate(xmlDocPtr
     xmlCharEncoding enc;
 
     if (((depth > 40) &&
-	((oldctxt == NULL) || (oldctxt->options & XML_PARSE_HUGE) == 0)) ||
+	((oldctxt == NULL) ||
+	 ((oldctxt->options & XML_PARSER_HUGE_BUT_ENT) == 0))) ||
 	(depth > 1024)) {
 	return(XML_ERR_ENTITY_LOOP);
     }
@@ -13595,7 +13605,8 @@ xmlParseBalancedChunkMemoryInternal(xmlP
     int i;
 #endif
 
-    if (((oldctxt->depth > 40) && ((oldctxt->options & XML_PARSE_HUGE) == 0)) ||
+    if (((oldctxt->depth > 40) &&
+         ((oldctxt->options & XML_PARSER_HUGE_BUT_ENT) == 0)) ||
         (oldctxt->depth >  1024)) {
 	return(XML_ERR_ENTITY_LOOP);
     }
@@ -15380,6 +15391,10 @@ xmlCtxtUseOptionsInternal(xmlParserCtxtP
 	ctxt->options |= XML_PARSE_BIG_LINES;
         options -= XML_PARSE_BIG_LINES;
     }
+    if (options & XML_PARSE_CHECK_ENT) {
+	ctxt->options |= XML_PARSE_CHECK_ENT;
+        options -= XML_PARSE_CHECK_ENT;
+    }
     ctxt->linenumbers = 1;
     return (options);
 }
