Diff for /embedaddon/libxml2/parser.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/07/22 01:22:20 version 1.1.1.3, 2014/06/15 19:53:29
Line 17 Line 17
  * parserInternals.c to reduce this file size.   * parserInternals.c to reduce this file size.
  * As much as possible the functions are associated with their relative   * As much as possible the functions are associated with their relative
  * production in the XML specification. A few productions defining the   * production in the XML specification. A few productions defining the
 * different ranges of character are actually implanted either in  * different ranges of character are actually implanted either in
  * parserInternals.h or parserInternals.c   * parserInternals.h or parserInternals.c
  * The DOM tree build is realized from the default SAX callbacks in   * The DOM tree build is realized from the default SAX callbacks in
  * the module SAX.c.   * the module SAX.c.
Line 40 Line 40
 #endif  #endif
   
 #include <stdlib.h>  #include <stdlib.h>
   #include <limits.h>
 #include <string.h>  #include <string.h>
 #include <stdarg.h>  #include <stdarg.h>
 #include <libxml/xmlmemory.h>  #include <libxml/xmlmemory.h>
Line 83 Line 84
 #include <lzma.h>  #include <lzma.h>
 #endif  #endif
   
   #include "buf.h"
   #include "enc.h"
   
 static void  static void
 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info);  xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info);
   
Line 117  xmlCreateEntityParserCtxtInternal(const xmlChar *URL,  Line 121  xmlCreateEntityParserCtxtInternal(const xmlChar *URL, 
  * parser option.   * parser option.
  */   */
 static int  static int
xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned long size,xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
                     xmlEntityPtr ent)                     xmlEntityPtr ent, size_t replacement)
 {  {
    unsigned long consumed = 0;    size_t consumed = 0;
   
     if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))      if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
         return (0);          return (0);
     if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)      if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
         return (1);          return (1);
    if (size != 0) {    if (replacement != 0) {
         if (replacement < XML_MAX_TEXT_LENGTH)
             return(0);
 
         /*          /*
            * If the volume of entity copy reaches 10 times the
            * amount of parsed data and over the large text threshold
            * then that's very likely to be an abuse.
            */
           if (ctxt->input != NULL) {
               consumed = ctxt->input->consumed +
                          (ctxt->input->cur - ctxt->input->base);
           }
           consumed += ctxt->sizeentities;
   
           if (replacement < XML_PARSER_NON_LINEAR * consumed)
               return(0);
       } else if (size != 0) {
           /*
          * Do the check based on the replacement size of the entity           * Do the check based on the replacement size of the entity
          */           */
         if (size < XML_PARSER_BIG_ENTITY)          if (size < XML_PARSER_BIG_ENTITY)
Line 149  xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned l Line 170  xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned l
         /*          /*
          * use the number of parsed entities in the replacement           * use the number of parsed entities in the replacement
          */           */
        size = ent->checked;        size = ent->checked / 2;
   
         /*          /*
          * The amount of data parsed counting entities size only once           * The amount of data parsed counting entities size only once
Line 172  xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned l Line 193  xmlParserEntityCheck(xmlParserCtxtPtr ctxt, unsigned l
          */           */
         return (0);          return (0);
     }      }
   
     xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);      xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
     return (1);      return (1);
 }  }
Line 194  unsigned int xmlParserMaxDepth = 256; Line 214  unsigned int xmlParserMaxDepth = 256;
 #define XML_PARSER_BUFFER_SIZE 100  #define XML_PARSER_BUFFER_SIZE 100
 #define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document"  #define SAX_COMPAT_MODE BAD_CAST "SAX compatibility mode document"
   
   /**
    * XML_PARSER_CHUNK_SIZE
    *
    * When calling GROW that's the minimal amount of data
    * the parser expected to have received. It is not a hard
    * limit but an optimization when reading strings like Names
    * It is not strictly needed as long as inputs available characters
    * are followed by 0, which should be provided by the I/O level
    */
   #define XML_PARSER_CHUNK_SIZE 100
   
 /*  /*
  * List of XML prefixed PI allowed by W3C specs   * List of XML prefixed PI allowed by W3C specs
  */   */
Line 233  xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityP Line 264  xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityP
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Some factorized error routines                          * *                Some factorized error routines                          *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 285  static void Line 316  static void
 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)  xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
 {  {
     const char *errmsg;      const char *errmsg;
       char errstr[129] = "";
   
     if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&      if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
         (ctxt->instate == XML_PARSER_EOF))          (ctxt->instate == XML_PARSER_EOF))
         return;          return;
     switch (error) {      switch (error) {
         case XML_ERR_INVALID_HEX_CHARREF:          case XML_ERR_INVALID_HEX_CHARREF:
            errmsg = "CharRef: invalid hexadecimal value\n";            errmsg = "CharRef: invalid hexadecimal value";
             break;              break;
         case XML_ERR_INVALID_DEC_CHARREF:          case XML_ERR_INVALID_DEC_CHARREF:
            errmsg = "CharRef: invalid decimal value\n";            errmsg = "CharRef: invalid decimal value";
             break;              break;
         case XML_ERR_INVALID_CHARREF:          case XML_ERR_INVALID_CHARREF:
            errmsg = "CharRef: invalid value\n";            errmsg = "CharRef: invalid value";
             break;              break;
         case XML_ERR_INTERNAL_ERROR:          case XML_ERR_INTERNAL_ERROR:
             errmsg = "internal error";              errmsg = "internal error";
             break;              break;
         case XML_ERR_PEREF_AT_EOF:          case XML_ERR_PEREF_AT_EOF:
            errmsg = "PEReference at end of document\n";            errmsg = "PEReference at end of document";
             break;              break;
         case XML_ERR_PEREF_IN_PROLOG:          case XML_ERR_PEREF_IN_PROLOG:
            errmsg = "PEReference in prolog\n";            errmsg = "PEReference in prolog";
             break;              break;
         case XML_ERR_PEREF_IN_EPILOG:          case XML_ERR_PEREF_IN_EPILOG:
            errmsg = "PEReference in epilog\n";            errmsg = "PEReference in epilog";
             break;              break;
         case XML_ERR_PEREF_NO_NAME:          case XML_ERR_PEREF_NO_NAME:
            errmsg = "PEReference: no name\n";            errmsg = "PEReference: no name";
             break;              break;
         case XML_ERR_PEREF_SEMICOL_MISSING:          case XML_ERR_PEREF_SEMICOL_MISSING:
            errmsg = "PEReference: expecting ';'\n";            errmsg = "PEReference: expecting ';'";
             break;              break;
         case XML_ERR_ENTITY_LOOP:          case XML_ERR_ENTITY_LOOP:
            errmsg = "Detected an entity reference loop\n";            errmsg = "Detected an entity reference loop";
             break;              break;
         case XML_ERR_ENTITY_NOT_STARTED:          case XML_ERR_ENTITY_NOT_STARTED:
            errmsg = "EntityValue: \" or ' expected\n";            errmsg = "EntityValue: \" or ' expected";
             break;              break;
         case XML_ERR_ENTITY_PE_INTERNAL:          case XML_ERR_ENTITY_PE_INTERNAL:
            errmsg = "PEReferences forbidden in internal subset\n";            errmsg = "PEReferences forbidden in internal subset";
             break;              break;
         case XML_ERR_ENTITY_NOT_FINISHED:          case XML_ERR_ENTITY_NOT_FINISHED:
            errmsg = "EntityValue: \" or ' expected\n";            errmsg = "EntityValue: \" or ' expected";
             break;              break;
         case XML_ERR_ATTRIBUTE_NOT_STARTED:          case XML_ERR_ATTRIBUTE_NOT_STARTED:
            errmsg = "AttValue: \" or ' expected\n";            errmsg = "AttValue: \" or ' expected";
             break;              break;
         case XML_ERR_LT_IN_ATTRIBUTE:          case XML_ERR_LT_IN_ATTRIBUTE:
            errmsg = "Unescaped '<' not allowed in attributes values\n";            errmsg = "Unescaped '<' not allowed in attributes values";
             break;              break;
         case XML_ERR_LITERAL_NOT_STARTED:          case XML_ERR_LITERAL_NOT_STARTED:
            errmsg = "SystemLiteral \" or ' expected\n";            errmsg = "SystemLiteral \" or ' expected";
             break;              break;
         case XML_ERR_LITERAL_NOT_FINISHED:          case XML_ERR_LITERAL_NOT_FINISHED:
            errmsg = "Unfinished System or Public ID \" or ' expected\n";            errmsg = "Unfinished System or Public ID \" or ' expected";
             break;              break;
         case XML_ERR_MISPLACED_CDATA_END:          case XML_ERR_MISPLACED_CDATA_END:
            errmsg = "Sequence ']]>' not allowed in content\n";            errmsg = "Sequence ']]>' not allowed in content";
             break;              break;
         case XML_ERR_URI_REQUIRED:          case XML_ERR_URI_REQUIRED:
            errmsg = "SYSTEM or PUBLIC, the URI is missing\n";            errmsg = "SYSTEM or PUBLIC, the URI is missing";
             break;              break;
         case XML_ERR_PUBID_REQUIRED:          case XML_ERR_PUBID_REQUIRED:
            errmsg = "PUBLIC, the Public Identifier is missing\n";            errmsg = "PUBLIC, the Public Identifier is missing";
             break;              break;
         case XML_ERR_HYPHEN_IN_COMMENT:          case XML_ERR_HYPHEN_IN_COMMENT:
            errmsg = "Comment must not contain '--' (double-hyphen)\n";            errmsg = "Comment must not contain '--' (double-hyphen)";
             break;              break;
         case XML_ERR_PI_NOT_STARTED:          case XML_ERR_PI_NOT_STARTED:
            errmsg = "xmlParsePI : no target name\n";            errmsg = "xmlParsePI : no target name";
             break;              break;
         case XML_ERR_RESERVED_XML_NAME:          case XML_ERR_RESERVED_XML_NAME:
            errmsg = "Invalid PI name\n";            errmsg = "Invalid PI name";
             break;              break;
         case XML_ERR_NOTATION_NOT_STARTED:          case XML_ERR_NOTATION_NOT_STARTED:
            errmsg = "NOTATION: Name expected here\n";            errmsg = "NOTATION: Name expected here";
             break;              break;
         case XML_ERR_NOTATION_NOT_FINISHED:          case XML_ERR_NOTATION_NOT_FINISHED:
            errmsg = "'>' required to close NOTATION declaration\n";            errmsg = "'>' required to close NOTATION declaration";
             break;              break;
         case XML_ERR_VALUE_REQUIRED:          case XML_ERR_VALUE_REQUIRED:
            errmsg = "Entity value required\n";            errmsg = "Entity value required";
             break;              break;
         case XML_ERR_URI_FRAGMENT:          case XML_ERR_URI_FRAGMENT:
             errmsg = "Fragment not allowed";              errmsg = "Fragment not allowed";
             break;              break;
         case XML_ERR_ATTLIST_NOT_STARTED:          case XML_ERR_ATTLIST_NOT_STARTED:
            errmsg = "'(' required to start ATTLIST enumeration\n";            errmsg = "'(' required to start ATTLIST enumeration";
             break;              break;
         case XML_ERR_NMTOKEN_REQUIRED:          case XML_ERR_NMTOKEN_REQUIRED:
            errmsg = "NmToken expected in ATTLIST enumeration\n";            errmsg = "NmToken expected in ATTLIST enumeration";
             break;              break;
         case XML_ERR_ATTLIST_NOT_FINISHED:          case XML_ERR_ATTLIST_NOT_FINISHED:
            errmsg = "')' required to finish ATTLIST enumeration\n";            errmsg = "')' required to finish ATTLIST enumeration";
             break;              break;
         case XML_ERR_MIXED_NOT_STARTED:          case XML_ERR_MIXED_NOT_STARTED:
            errmsg = "MixedContentDecl : '|' or ')*' expected\n";            errmsg = "MixedContentDecl : '|' or ')*' expected";
             break;              break;
         case XML_ERR_PCDATA_REQUIRED:          case XML_ERR_PCDATA_REQUIRED:
            errmsg = "MixedContentDecl : '#PCDATA' expected\n";            errmsg = "MixedContentDecl : '#PCDATA' expected";
             break;              break;
         case XML_ERR_ELEMCONTENT_NOT_STARTED:          case XML_ERR_ELEMCONTENT_NOT_STARTED:
            errmsg = "ContentDecl : Name or '(' expected\n";            errmsg = "ContentDecl : Name or '(' expected";
             break;              break;
         case XML_ERR_ELEMCONTENT_NOT_FINISHED:          case XML_ERR_ELEMCONTENT_NOT_FINISHED:
            errmsg = "ContentDecl : ',' '|' or ')' expected\n";            errmsg = "ContentDecl : ',' '|' or ')' expected";
             break;              break;
         case XML_ERR_PEREF_IN_INT_SUBSET:          case XML_ERR_PEREF_IN_INT_SUBSET:
             errmsg =              errmsg =
                "PEReference: forbidden within markup decl in internal subset\n";                "PEReference: forbidden within markup decl in internal subset";
             break;              break;
         case XML_ERR_GT_REQUIRED:          case XML_ERR_GT_REQUIRED:
            errmsg = "expected '>'\n";            errmsg = "expected '>'";
             break;              break;
         case XML_ERR_CONDSEC_INVALID:          case XML_ERR_CONDSEC_INVALID:
            errmsg = "XML conditional section '[' expected\n";            errmsg = "XML conditional section '[' expected";
             break;              break;
         case XML_ERR_EXT_SUBSET_NOT_FINISHED:          case XML_ERR_EXT_SUBSET_NOT_FINISHED:
            errmsg = "Content error in the external subset\n";            errmsg = "Content error in the external subset";
             break;              break;
         case XML_ERR_CONDSEC_INVALID_KEYWORD:          case XML_ERR_CONDSEC_INVALID_KEYWORD:
             errmsg =              errmsg =
                "conditional section INCLUDE or IGNORE keyword expected\n";                "conditional section INCLUDE or IGNORE keyword expected";
             break;              break;
         case XML_ERR_CONDSEC_NOT_FINISHED:          case XML_ERR_CONDSEC_NOT_FINISHED:
            errmsg = "XML conditional section not closed\n";            errmsg = "XML conditional section not closed";
             break;              break;
         case XML_ERR_XMLDECL_NOT_STARTED:          case XML_ERR_XMLDECL_NOT_STARTED:
            errmsg = "Text declaration '<?xml' required\n";            errmsg = "Text declaration '<?xml' required";
             break;              break;
         case XML_ERR_XMLDECL_NOT_FINISHED:          case XML_ERR_XMLDECL_NOT_FINISHED:
            errmsg = "parsing XML declaration: '?>' expected\n";            errmsg = "parsing XML declaration: '?>' expected";
             break;              break;
         case XML_ERR_EXT_ENTITY_STANDALONE:          case XML_ERR_EXT_ENTITY_STANDALONE:
            errmsg = "external parsed entities cannot be standalone\n";            errmsg = "external parsed entities cannot be standalone";
             break;              break;
         case XML_ERR_ENTITYREF_SEMICOL_MISSING:          case XML_ERR_ENTITYREF_SEMICOL_MISSING:
            errmsg = "EntityRef: expecting ';'\n";            errmsg = "EntityRef: expecting ';'";
             break;              break;
         case XML_ERR_DOCTYPE_NOT_FINISHED:          case XML_ERR_DOCTYPE_NOT_FINISHED:
            errmsg = "DOCTYPE improperly terminated\n";            errmsg = "DOCTYPE improperly terminated";
             break;              break;
         case XML_ERR_LTSLASH_REQUIRED:          case XML_ERR_LTSLASH_REQUIRED:
            errmsg = "EndTag: '</' not found\n";            errmsg = "EndTag: '</' not found";
             break;              break;
         case XML_ERR_EQUAL_REQUIRED:          case XML_ERR_EQUAL_REQUIRED:
            errmsg = "expected '='\n";            errmsg = "expected '='";
             break;              break;
         case XML_ERR_STRING_NOT_CLOSED:          case XML_ERR_STRING_NOT_CLOSED:
            errmsg = "String not closed expecting \" or '\n";            errmsg = "String not closed expecting \" or '";
             break;              break;
         case XML_ERR_STRING_NOT_STARTED:          case XML_ERR_STRING_NOT_STARTED:
            errmsg = "String not started expecting ' or \"\n";            errmsg = "String not started expecting ' or \"";
             break;              break;
         case XML_ERR_ENCODING_NAME:          case XML_ERR_ENCODING_NAME:
            errmsg = "Invalid XML encoding name\n";            errmsg = "Invalid XML encoding name";
             break;              break;
         case XML_ERR_STANDALONE_VALUE:          case XML_ERR_STANDALONE_VALUE:
            errmsg = "standalone accepts only 'yes' or 'no'\n";            errmsg = "standalone accepts only 'yes' or 'no'";
             break;              break;
         case XML_ERR_DOCUMENT_EMPTY:          case XML_ERR_DOCUMENT_EMPTY:
            errmsg = "Document is empty\n";            errmsg = "Document is empty";
             break;              break;
         case XML_ERR_DOCUMENT_END:          case XML_ERR_DOCUMENT_END:
            errmsg = "Extra content at the end of the document\n";            errmsg = "Extra content at the end of the document";
             break;              break;
         case XML_ERR_NOT_WELL_BALANCED:          case XML_ERR_NOT_WELL_BALANCED:
            errmsg = "chunk is not well balanced\n";            errmsg = "chunk is not well balanced";
             break;              break;
         case XML_ERR_EXTRA_CONTENT:          case XML_ERR_EXTRA_CONTENT:
            errmsg = "extra content at the end of well balanced chunk\n";            errmsg = "extra content at the end of well balanced chunk";
             break;              break;
         case XML_ERR_VERSION_MISSING:          case XML_ERR_VERSION_MISSING:
            errmsg = "Malformed declaration expecting version\n";            errmsg = "Malformed declaration expecting version";
             break;              break;
           case XML_ERR_NAME_TOO_LONG:
               errmsg = "Name too long use XML_PARSE_HUGE option";
               break;
 #if 0  #if 0
         case:          case:
            errmsg = "\n";            errmsg = "";
             break;              break;
 #endif  #endif
         default:          default:
            errmsg = "Unregistered error message\n";            errmsg = "Unregistered error message";
     }      }
       if (info == NULL)
           snprintf(errstr, 128, "%s\n", errmsg);
       else
           snprintf(errstr, 128, "%s: %%s\n", errmsg);
     if (ctxt != NULL)      if (ctxt != NULL)
         ctxt->errNo = error;          ctxt->errNo = error;
     __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,      __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
                    XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, errmsg,                    XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, &errstr[0],
                     info);                      info);
     if (ctxt != NULL) {      if (ctxt != NULL) {
         ctxt->wellFormed = 0;          ctxt->wellFormed = 0;
Line 626  xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErro Line 665  xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErro
  */   */
 static void  static void
 xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,  xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                  const char *msg, const xmlChar *str1, int val,                   const char *msg, const xmlChar *str1, int val,
                   const xmlChar *str2)                    const xmlChar *str2)
 {  {
     if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&      if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
Line 754  xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error Line 793  xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Library wide options                                    * *                Library wide options                                    *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 978  xmlHasFeature(xmlFeature feature) Line 1017  xmlHasFeature(xmlFeature feature)
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              SAX2 defaulted attributes handling                      * *                SAX2 defaulted attributes handling                      *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 1002  xmlDetectSAX2(xmlParserCtxtPtr ctxt) { Line 1041  xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
     ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);      ctxt->str_xml = xmlDictLookup(ctxt->dict, BAD_CAST "xml", 3);
     ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);      ctxt->str_xmlns = xmlDictLookup(ctxt->dict, BAD_CAST "xmlns", 5);
     ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);      ctxt->str_xml_ns = xmlDictLookup(ctxt->dict, XML_XML_NAMESPACE, 36);
    if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||     if ((ctxt->str_xml==NULL) || (ctxt->str_xmlns==NULL) ||
                (ctxt->str_xml_ns == NULL)) {                (ctxt->str_xml_ns == NULL)) {
         xmlErrMemory(ctxt, NULL);          xmlErrMemory(ctxt, NULL);
     }      }
 }  }
Line 1517  nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, c Line 1556  nsPush(xmlParserCtxtPtr ctxt, const xmlChar *prefix, c
 {  {
     if (ctxt->options & XML_PARSE_NSCLEAN) {      if (ctxt->options & XML_PARSE_NSCLEAN) {
         int i;          int i;
        for (i = 0;i < ctxt->nsNr;i += 2) {        for (i = ctxt->nsNr - 2;i >= 0;i -= 2) {
             if (ctxt->nsTab[i] == prefix) {              if (ctxt->nsTab[i] == prefix) {
                 /* in scope */                  /* in scope */
                 if (ctxt->nsTab[i + 1] == URL)                  if (ctxt->nsTab[i + 1] == URL)
Line 1922  static int spacePop(xmlParserCtxtPtr ctxt) { Line 1961  static int spacePop(xmlParserCtxtPtr ctxt) {
  *           to compare on ASCII based substring.   *           to compare on ASCII based substring.
  *   SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined   *   SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined
  *           strings without newlines within the parser.   *           strings without newlines within the parser.
 *   NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline ASCII  *   NEXT1(l) Skip 1 xmlChar, and must also be used only to skip 1 non-newline ASCII
  *           defined char within the parser.   *           defined char within the parser.
  * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding   * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding
  *   *
Line 1971  static int spacePop(xmlParserCtxtPtr ctxt) { Line 2010  static int spacePop(xmlParserCtxtPtr ctxt) {
 #define SKIPL(val) do {                                                 \  #define SKIPL(val) do {                                                 \
     int skipl;                                                          \      int skipl;                                                          \
     for(skipl=0; skipl<val; skipl++) {                                  \      for(skipl=0; skipl<val; skipl++) {                                  \
        if (*(ctxt->input->cur) == '\n') {                              \        if (*(ctxt->input->cur) == '\n') {                              \
         ctxt->input->line++; ctxt->input->col = 1;                      \          ctxt->input->line++; ctxt->input->col = 1;                      \
        } else ctxt->input->col++;                                      \        } else ctxt->input->col++;                                      \
        ctxt->nbChars++;                                                \        ctxt->nbChars++;                                                \
         ctxt->input->cur++;                                             \          ctxt->input->cur++;                                             \
     }                                                                   \      }                                                                   \
     if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);     \      if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);     \
Line 2000  static void xmlSHRINK (xmlParserCtxtPtr ctxt) { Line 2039  static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
         xmlGROW (ctxt);          xmlGROW (ctxt);
   
 static void xmlGROW (xmlParserCtxtPtr ctxt) {  static void xmlGROW (xmlParserCtxtPtr ctxt) {
       if ((((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
            ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
            ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputReadCallback) xmlNop)) &&
           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
           xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
           ctxt->instate = XML_PARSER_EOF;
       }
     xmlParserInputGrow(ctxt->input, INPUT_CHUNK);      xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
     if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) &&      if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0) &&
         (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))          (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
Line 2144  xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr  Line 2190  xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr 
                 "Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur);                  "Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur);
     }      }
     ret = inputPush(ctxt, input);      ret = inputPush(ctxt, input);
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
     GROW;      GROW;
     return(ret);      return(ret);
 }  }
Line 2159  xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr  Line 2207  xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr 
  *   *
  * [ WFC: Legal Character ]   * [ WFC: Legal Character ]
  * Characters referred to using character references must match the   * Characters referred to using character references must match the
 * production for Char.  * production for Char.
  *   *
  * Returns the value parsed (as an int), 0 in case of error   * Returns the value parsed (as an int), 0 in case of error
  */   */
Line 2180  xmlParseCharRef(xmlParserCtxtPtr ctxt) { Line 2228  xmlParseCharRef(xmlParserCtxtPtr ctxt) {
             if (count++ > 20) {              if (count++ > 20) {
                 count = 0;                  count = 0;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(0);
             }              }
            if ((RAW >= '0') && (RAW <= '9'))             if ((RAW >= '0') && (RAW <= '9'))
                 val = val * 16 + (CUR - '0');                  val = val * 16 + (CUR - '0');
             else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20))              else if ((RAW >= 'a') && (RAW <= 'f') && (count < 20))
                 val = val * 16 + (CUR - 'a') + 10;                  val = val * 16 + (CUR - 'a') + 10;
Line 2211  xmlParseCharRef(xmlParserCtxtPtr ctxt) { Line 2261  xmlParseCharRef(xmlParserCtxtPtr ctxt) {
             if (count++ > 20) {              if (count++ > 20) {
                 count = 0;                  count = 0;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(0);
             }              }
            if ((RAW >= '0') && (RAW <= '9'))             if ((RAW >= '0') && (RAW <= '9'))
                 val = val * 10 + (CUR - '0');                  val = val * 10 + (CUR - '0');
             else {              else {
                 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);                  xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);
Line 2238  xmlParseCharRef(xmlParserCtxtPtr ctxt) { Line 2290  xmlParseCharRef(xmlParserCtxtPtr ctxt) {
     /*      /*
      * [ WFC: Legal Character ]       * [ WFC: Legal Character ]
      * Characters referred to using character references must match the       * Characters referred to using character references must match the
     * production for Char.      * production for Char.
      */       */
     if ((IS_CHAR(val) && (outofrange == 0))) {      if ((IS_CHAR(val) && (outofrange == 0))) {
         return(val);          return(val);
Line 2263  xmlParseCharRef(xmlParserCtxtPtr ctxt) { Line 2315  xmlParseCharRef(xmlParserCtxtPtr ctxt) {
  *   *
  * [ WFC: Legal Character ]   * [ WFC: Legal Character ]
  * Characters referred to using character references must match the   * Characters referred to using character references must match the
 * production for Char.  * production for Char.
  *   *
  * Returns the value parsed (as an int), 0 in case of error, str will be   * Returns the value parsed (as an int), 0 in case of error, str will be
  *         updated to the current value of the index   *         updated to the current value of the index
Line 2282  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml Line 2334  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml
         ptr += 3;          ptr += 3;
         cur = *ptr;          cur = *ptr;
         while (cur != ';') { /* Non input consuming loop */          while (cur != ';') { /* Non input consuming loop */
            if ((cur >= '0') && (cur <= '9'))             if ((cur >= '0') && (cur <= '9'))
                 val = val * 16 + (cur - '0');                  val = val * 16 + (cur - '0');
             else if ((cur >= 'a') && (cur <= 'f'))              else if ((cur >= 'a') && (cur <= 'f'))
                 val = val * 16 + (cur - 'a') + 10;                  val = val * 16 + (cur - 'a') + 10;
Line 2305  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml Line 2357  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml
         ptr += 2;          ptr += 2;
         cur = *ptr;          cur = *ptr;
         while (cur != ';') { /* Non input consuming loops */          while (cur != ';') { /* Non input consuming loops */
            if ((cur >= '0') && (cur <= '9'))             if ((cur >= '0') && (cur <= '9'))
                 val = val * 10 + (cur - '0');                  val = val * 10 + (cur - '0');
             else {              else {
                 xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);                  xmlFatalErr(ctxt, XML_ERR_INVALID_DEC_CHARREF, NULL);
Line 2329  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml Line 2381  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml
     /*      /*
      * [ WFC: Legal Character ]       * [ WFC: Legal Character ]
      * Characters referred to using character references must match the       * Characters referred to using character references must match the
     * production for Char.      * production for Char.
      */       */
     if ((IS_CHAR(val) && (outofrange == 0))) {      if ((IS_CHAR(val) && (outofrange == 0))) {
         return(val);          return(val);
Line 2351  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml Line 2403  xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xml
  *   *
  * Returns the new input stream or NULL   * Returns the new input stream or NULL
  */   */
 
 static void deallocblankswrapper (xmlChar *str) {xmlFree(str);}  static void deallocblankswrapper (xmlChar *str) {xmlFree(str);}
 
 static xmlParserInputPtr  static xmlParserInputPtr
 xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
     xmlParserInputPtr input;      xmlParserInputPtr input;
Line 2376  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt,  Line 2428  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, 
     if (buffer == NULL) {      if (buffer == NULL) {
         xmlErrMemory(ctxt, NULL);          xmlErrMemory(ctxt, NULL);
         xmlFree(input);          xmlFree(input);
        return(NULL);        return(NULL);
     }      }
     buffer [0] = ' ';      buffer [0] = ' ';
     buffer [1] = '%';      buffer [1] = '%';
Line 2395  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt,  Line 2447  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, 
 /**  /**
  * xmlParserHandlePEReference:   * xmlParserHandlePEReference:
  * @ctxt:  the parser context   * @ctxt:  the parser context
 *  *
  * [69] PEReference ::= '%' Name ';'   * [69] PEReference ::= '%' Name ';'
  *   *
  * [ WFC: No Recursion ]   * [ WFC: No Recursion ]
  * A parsed entity must not contain a recursive   * A parsed entity must not contain a recursive
 * reference to itself, either directly or indirectly.  * reference to itself, either directly or indirectly.
  *   *
  * [ WFC: Entity Declared ]   * [ WFC: Entity Declared ]
  * In a document without any DTD, a document with only an internal DTD   * In a document without any DTD, a document with only an internal DTD
Line 2418  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt,  Line 2470  xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, 
  * NOTE: misleading but this is handled.   * NOTE: misleading but this is handled.
  *   *
  * A PEReference may have been detected in the current input stream   * A PEReference may have been detected in the current input stream
 * the handling is done accordingly to  * the handling is done accordingly to
  *      http://www.w3.org/TR/REC-xml#entproc   *      http://www.w3.org/TR/REC-xml#entproc
 * i.e.  * i.e.
  *   - Included in literal in entity values   *   - Included in literal in entity values
  *   - Included as Parameter Entity reference within DTDs   *   - Included as Parameter Entity reference within DTDs
  */   */
Line 2497  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2549  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
             NEXT;              NEXT;
             if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL))              if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity != NULL))
                 entity = ctxt->sax->getParameterEntity(ctxt->userData, name);                  entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
               if (ctxt->instate == XML_PARSER_EOF)
                   return;
             if (entity == NULL) {              if (entity == NULL) {
                
                 /*                  /*
                  * [ WFC: Entity Declared ]                   * [ WFC: Entity Declared ]
                  * In a document without any DTD, a document with only an                   * In a document without any DTD, a document with only an
Line 2524  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2578  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
                         xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,                          xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
                                          "PEReference: %%%s; not found\n",                                           "PEReference: %%%s; not found\n",
                                          name, NULL);                                           name, NULL);
                    } else                     } else
                         xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,                          xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
                                       "PEReference: %%%s; not found\n",                                        "PEReference: %%%s; not found\n",
                                       name, NULL);                                        name, NULL);
Line 2549  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2603  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
                     if (xmlPushInput(ctxt, input) < 0)                      if (xmlPushInput(ctxt, input) < 0)
                         return;                          return;
   
                    /*                     /*
                      * Get the 4 first bytes and decode the charset                       * Get the 4 first bytes and decode the charset
                      * if enc != XML_CHAR_ENCODING_NONE                       * if enc != XML_CHAR_ENCODING_NONE
                      * plug some encoding conversion routines.                       * plug some encoding conversion routines.
Line 2559  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2613  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
                      * the amount of data in the buffer.                       * the amount of data in the buffer.
                      */                       */
                     GROW                      GROW
                       if (ctxt->instate == XML_PARSER_EOF)
                           return;
                     if ((ctxt->input->end - ctxt->input->cur)>=4) {                      if ((ctxt->input->end - ctxt->input->cur)>=4) {
                         start[0] = RAW;                          start[0] = RAW;
                         start[1] = NXT(1);                          start[1] = NXT(1);
Line 2589  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2645  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
   
 /*  /*
  * Macro used to grow the current buffer.   * Macro used to grow the current buffer.
    * buffer##_size is expected to be a size_t
    * mem_error: is expected to handle memory allocation failures
  */   */
 #define growBuffer(buffer, n) {                                         \  #define growBuffer(buffer, n) {                                         \
     xmlChar *tmp;                                                       \      xmlChar *tmp;                                                       \
    buffer##_size *= 2;                                                    \    size_t new_size = buffer##_size * 2 + n;                            \
    buffer##_size += n;                                                        \    if (new_size < buffer##_size) goto mem_error;                       \
    tmp = (xmlChar *)                                                   \    tmp = (xmlChar *) xmlRealloc(buffer, new_size);                     \
                xmlRealloc(buffer, buffer##_size * sizeof(xmlChar));     \ 
     if (tmp == NULL) goto mem_error;                                    \      if (tmp == NULL) goto mem_error;                                    \
     buffer = tmp;                                                       \      buffer = tmp;                                                       \
       buffer##_size = new_size;                                           \
 }  }
   
 /**  /**
Line 2609  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { Line 2667  xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
  * @end:  an end marker xmlChar, 0 if none   * @end:  an end marker xmlChar, 0 if none
  * @end2:  an end marker xmlChar, 0 if none   * @end2:  an end marker xmlChar, 0 if none
  * @end3:  an end marker xmlChar, 0 if none   * @end3:  an end marker xmlChar, 0 if none
 *  *
  * Takes a entity string content and process to do the adequate substitutions.   * Takes a entity string content and process to do the adequate substitutions.
  *   *
  * [67] Reference ::= EntityRef | CharRef   * [67] Reference ::= EntityRef | CharRef
Line 2623  xmlChar * Line 2681  xmlChar *
 xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
                       int what, xmlChar end, xmlChar  end2, xmlChar end3) {                        int what, xmlChar end, xmlChar  end2, xmlChar end3) {
     xmlChar *buffer = NULL;      xmlChar *buffer = NULL;
    int buffer_size = 0;    size_t buffer_size = 0;
     size_t nbchars = 0;
   
     xmlChar *current = NULL;      xmlChar *current = NULL;
     xmlChar *rep = NULL;      xmlChar *rep = NULL;
     const xmlChar *last;      const xmlChar *last;
     xmlEntityPtr ent;      xmlEntityPtr ent;
     int c,l;      int c,l;
     int nbchars = 0;  
   
     if ((ctxt == NULL) || (str == NULL) || (len < 0))      if ((ctxt == NULL) || (str == NULL) || (len < 0))
         return(NULL);          return(NULL);
Line 2647  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2705  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
      * allocate a translation buffer.       * allocate a translation buffer.
      */       */
     buffer_size = XML_PARSER_BIG_BUFFER_SIZE;      buffer_size = XML_PARSER_BIG_BUFFER_SIZE;
    buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar));    buffer = (xmlChar *) xmlMallocAtomic(buffer_size);
     if (buffer == NULL) goto mem_error;      if (buffer == NULL) goto mem_error;
   
     /*      /*
Line 2667  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2725  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
             if (val != 0) {              if (val != 0) {
                 COPY_BUF(0,buffer,nbchars,val);                  COPY_BUF(0,buffer,nbchars,val);
             }              }
            if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {            if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
                 growBuffer(buffer, XML_PARSER_BUFFER_SIZE);                  growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
             }              }
         } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {          } else if ((c == '&') && (what & XML_SUBSTITUTE_REF)) {
Line 2680  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2738  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
                 (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))                  (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
                 goto int_error;                  goto int_error;
             if (ent != NULL)              if (ent != NULL)
                ctxt->nbentities += ent->checked;                ctxt->nbentities += ent->checked / 2;
             if ((ent != NULL) &&              if ((ent != NULL) &&
                 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {                  (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
                 if (ent->content != NULL) {                  if (ent->content != NULL) {
                     COPY_BUF(0,buffer,nbchars,ent->content[0]);                      COPY_BUF(0,buffer,nbchars,ent->content[0]);
                    if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {                    if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
                         growBuffer(buffer, XML_PARSER_BUFFER_SIZE);                          growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
                     }                      }
                 } else {                  } else {
Line 2702  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2760  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
                     current = rep;                      current = rep;
                     while (*current != 0) { /* non input consuming loop */                      while (*current != 0) { /* non input consuming loop */
                         buffer[nbchars++] = *current++;                          buffer[nbchars++] = *current++;
                        if (nbchars >                        if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
                            buffer_size - XML_PARSER_BUFFER_SIZE) {                            if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
                            if (xmlParserEntityCheck(ctxt, nbchars, ent)) 
                                 goto int_error;                                  goto int_error;
                             growBuffer(buffer, XML_PARSER_BUFFER_SIZE);                              growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
                         }                          }
Line 2717  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2774  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
                 const xmlChar *cur = ent->name;                  const xmlChar *cur = ent->name;
   
                 buffer[nbchars++] = '&';                  buffer[nbchars++] = '&';
                if (nbchars > buffer_size - i - XML_PARSER_BUFFER_SIZE) {                if (nbchars + i + XML_PARSER_BUFFER_SIZE > buffer_size) {
                     growBuffer(buffer, i + XML_PARSER_BUFFER_SIZE);                      growBuffer(buffer, i + XML_PARSER_BUFFER_SIZE);
                 }                  }
                 for (;i > 0;i--)                  for (;i > 0;i--)
Line 2732  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2789  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
             if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)              if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
                 goto int_error;                  goto int_error;
             if (ent != NULL)              if (ent != NULL)
                ctxt->nbentities += ent->checked;                ctxt->nbentities += ent->checked / 2;
             if (ent != NULL) {              if (ent != NULL) {
                 if (ent->content == NULL) {                  if (ent->content == NULL) {
                     xmlLoadEntityContent(ctxt, ent);                      xmlLoadEntityContent(ctxt, ent);
Line 2745  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2802  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
                     current = rep;                      current = rep;
                     while (*current != 0) { /* non input consuming loop */                      while (*current != 0) { /* non input consuming loop */
                         buffer[nbchars++] = *current++;                          buffer[nbchars++] = *current++;
                        if (nbchars >                        if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
                            buffer_size - XML_PARSER_BUFFER_SIZE) {                            if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
                            if (xmlParserEntityCheck(ctxt, nbchars, ent)) 
                                 goto int_error;                                  goto int_error;
                             growBuffer(buffer, XML_PARSER_BUFFER_SIZE);                              growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
                         }                          }
Line 2759  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons Line 2815  xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, cons
         } else {          } else {
             COPY_BUF(l,buffer,nbchars,c);              COPY_BUF(l,buffer,nbchars,c);
             str += l;              str += l;
            if (nbchars > buffer_size - XML_PARSER_BUFFER_SIZE) {            if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
              growBuffer(buffer, XML_PARSER_BUFFER_SIZE);                growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
             }              }
         }          }
         if (str < last)          if (str < last)
Line 2789  int_error: Line 2845  int_error:
  * @end:  an end marker xmlChar, 0 if none   * @end:  an end marker xmlChar, 0 if none
  * @end2:  an end marker xmlChar, 0 if none   * @end2:  an end marker xmlChar, 0 if none
  * @end3:  an end marker xmlChar, 0 if none   * @end3:  an end marker xmlChar, 0 if none
 *  *
  * Takes a entity string content and process to do the adequate substitutions.   * Takes a entity string content and process to do the adequate substitutions.
  *   *
  * [67] Reference ::= EntityRef | CharRef   * [67] Reference ::= EntityRef | CharRef
Line 3152  xmlIsNameChar(xmlParserCtxtPtr ctxt, int c) { Line 3208  xmlIsNameChar(xmlParserCtxtPtr ctxt, int c) {
     } else {      } else {
         if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||          if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
             (c == '.') || (c == '-') ||              (c == '.') || (c == '-') ||
            (c == '_') || (c == ':') ||             (c == '_') || (c == ':') ||
             (IS_COMBINING(c)) ||              (IS_COMBINING(c)) ||
             (IS_EXTENDER(c)))              (IS_EXTENDER(c)))
             return(1);              return(1);
Line 3177  xmlParseNameComplex(xmlParserCtxtPtr ctxt) { Line 3233  xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
      * Handler for more complex cases       * Handler for more complex cases
      */       */
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return(NULL);
     c = CUR_CHAR(l);      c = CUR_CHAR(l);
     if ((ctxt->options & XML_PARSE_OLD10) == 0) {      if ((ctxt->options & XML_PARSE_OLD10) == 0) {
         /*          /*
Line 3225  xmlParseNameComplex(xmlParserCtxtPtr ctxt) { Line 3283  xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
                 ((c >= 0xFDF0) && (c <= 0xFFFD)) ||                  ((c >= 0xFDF0) && (c <= 0xFFFD)) ||
                 ((c >= 0x10000) && (c <= 0xEFFFF))                  ((c >= 0x10000) && (c <= 0xEFFFF))
                 )) {                  )) {
            if (count++ > 100) {            if (count++ > XML_PARSER_CHUNK_SIZE) {
                 count = 0;                  count = 0;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
             }              }
             len += l;              len += l;
             NEXTL(l);              NEXTL(l);
Line 3246  xmlParseNameComplex(xmlParserCtxtPtr ctxt) { Line 3306  xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
         while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */          while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
                ((IS_LETTER(c)) || (IS_DIGIT(c)) ||                 ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
                 (c == '.') || (c == '-') ||                  (c == '.') || (c == '-') ||
                (c == '_') || (c == ':') ||                 (c == '_') || (c == ':') ||
                 (IS_COMBINING(c)) ||                  (IS_COMBINING(c)) ||
                 (IS_EXTENDER(c)))) {                  (IS_EXTENDER(c)))) {
            if (count++ > 100) {            if (count++ > XML_PARSER_CHUNK_SIZE) {
                 count = 0;                  count = 0;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
             }              }
             len += l;              len += l;
             NEXTL(l);              NEXTL(l);
             c = CUR_CHAR(l);              c = CUR_CHAR(l);
               if (c == 0) {
                   count = 0;
                   GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
                   c = CUR_CHAR(l);
               }
         }          }
     }      }
       if ((len > XML_MAX_NAME_LENGTH) &&
           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
           return(NULL);
       }
     if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r'))      if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1] == '\r'))
         return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len));          return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len));
     return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));      return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
Line 3307  xmlParseName(xmlParserCtxtPtr ctxt) { Line 3381  xmlParseName(xmlParserCtxtPtr ctxt) {
             in++;              in++;
         if ((*in > 0) && (*in < 0x80)) {          if ((*in > 0) && (*in < 0x80)) {
             count = in - ctxt->input->cur;              count = in - ctxt->input->cur;
               if ((count > XML_MAX_NAME_LENGTH) &&
                   ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                   xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
                   return(NULL);
               }
             ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);              ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
             ctxt->input->cur = in;              ctxt->input->cur = in;
             ctxt->nbChars += count;              ctxt->nbChars += count;
Line 3342  xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) { Line 3421  xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
   
     while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */      while ((c != ' ') && (c != '>') && (c != '/') && /* test bigname.xml */
            (xmlIsNameChar(ctxt, c) && (c != ':'))) {             (xmlIsNameChar(ctxt, c) && (c != ':'))) {
        if (count++ > 100) {        if (count++ > XML_PARSER_CHUNK_SIZE) {
             if ((len > XML_MAX_NAME_LENGTH) &&
                 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
                 return(NULL);
             }
             count = 0;              count = 0;
             GROW;              GROW;
               if (ctxt->instate == XML_PARSER_EOF)
                   return(NULL);
         }          }
         len += l;          len += l;
         NEXTL(l);          NEXTL(l);
         c = CUR_CHAR(l);          c = CUR_CHAR(l);
           if (c == 0) {
               count = 0;
               GROW;
               if (ctxt->instate == XML_PARSER_EOF)
                   return(NULL);
               c = CUR_CHAR(l);
           }
     }      }
       if ((len > XML_MAX_NAME_LENGTH) &&
           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
           return(NULL);
       }
     return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));      return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
 }  }
   
 /**  /**
  * xmlParseNCName:   * xmlParseNCName:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 * @len:  lenght of the string parsed * @len:  length of the string parsed
  *   *
  * parse an XML name.   * parse an XML name.
  *   *
Line 3394  xmlParseNCName(xmlParserCtxtPtr ctxt) { Line 3492  xmlParseNCName(xmlParserCtxtPtr ctxt) {
             in++;              in++;
         if ((*in > 0) && (*in < 0x80)) {          if ((*in > 0) && (*in < 0x80)) {
             count = in - ctxt->input->cur;              count = in - ctxt->input->cur;
               if ((count > XML_MAX_NAME_LENGTH) &&
                   ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                   xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
                   return(NULL);
               }
             ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);              ret = xmlDictLookup(ctxt->dict, ctxt->input->cur, count);
             ctxt->input->cur = in;              ctxt->input->cur = in;
             ctxt->nbChars += count;              ctxt->nbChars += count;
Line 3425  xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar  Line 3528  xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar 
     const xmlChar *ret;      const xmlChar *ret;
   
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return(NULL);
   
     in = ctxt->input->cur;      in = ctxt->input->cur;
     while (*in != 0 && *in == *cmp) {      while (*in != 0 && *in == *cmp) {
Line 3460  xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar  Line 3565  xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar 
  *   *
  * [6] Names ::= Name (#x20 Name)*   * [6] Names ::= Name (#x20 Name)*
  *   *
 * Returns the Name parsed or NULL. The @str pointer  * Returns the Name parsed or NULL. The @str pointer
  * is updated to the current location in the string.   * is updated to the current location in the string.
  */   */
   
Line 3504  xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlCha Line 3609  xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlCha
             while (xmlIsNameChar(ctxt, c)) {              while (xmlIsNameChar(ctxt, c)) {
                 if (len + 10 > max) {                  if (len + 10 > max) {
                     xmlChar *tmp;                      xmlChar *tmp;
   
                       if ((len > XML_MAX_NAME_LENGTH) &&
                           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
                           xmlFree(buffer);
                           return(NULL);
                       }
                     max *= 2;                      max *= 2;
                     tmp = (xmlChar *) xmlRealloc(buffer,                      tmp = (xmlChar *) xmlRealloc(buffer,
                                                     max * sizeof(xmlChar));                                                      max * sizeof(xmlChar));
Line 3523  xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlCha Line 3635  xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlCha
             return(buffer);              return(buffer);
         }          }
     }      }
       if ((len > XML_MAX_NAME_LENGTH) &&
           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
           return(NULL);
       }
     *str = cur;      *str = cur;
     return(xmlStrndup(buf, len));      return(xmlStrndup(buf, len));
 }  }
Line 3552  xmlParseNmtoken(xmlParserCtxtPtr ctxt) { Line 3669  xmlParseNmtoken(xmlParserCtxtPtr ctxt) {
 #endif  #endif
   
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return(NULL);
     c = CUR_CHAR(l);      c = CUR_CHAR(l);
   
     while (xmlIsNameChar(ctxt, c)) {      while (xmlIsNameChar(ctxt, c)) {
        if (count++ > 100) {        if (count++ > XML_PARSER_CHUNK_SIZE) {
             count = 0;              count = 0;
             GROW;              GROW;
         }          }
         COPY_BUF(l,buf,len,c);          COPY_BUF(l,buf,len,c);
         NEXTL(l);          NEXTL(l);
         c = CUR_CHAR(l);          c = CUR_CHAR(l);
           if (c == 0) {
               count = 0;
               GROW;
               if (ctxt->instate == XML_PARSER_EOF)
                   return(NULL);
               c = CUR_CHAR(l);
           }
         if (len >= XML_MAX_NAMELEN) {          if (len >= XML_MAX_NAMELEN) {
             /*              /*
              * Okay someone managed to make a huge token, so he's ready to pay               * Okay someone managed to make a huge token, so he's ready to pay
Line 3577  xmlParseNmtoken(xmlParserCtxtPtr ctxt) { Line 3703  xmlParseNmtoken(xmlParserCtxtPtr ctxt) {
             }              }
             memcpy(buffer, buf, len);              memcpy(buffer, buf, len);
             while (xmlIsNameChar(ctxt, c)) {              while (xmlIsNameChar(ctxt, c)) {
                if (count++ > 100) {                if (count++ > XML_PARSER_CHUNK_SIZE) {
                     count = 0;                      count = 0;
                     GROW;                      GROW;
                       if (ctxt->instate == XML_PARSER_EOF) {
                           xmlFree(buffer);
                           return(NULL);
                       }
                 }                  }
                 if (len + 10 > max) {                  if (len + 10 > max) {
                     xmlChar *tmp;                      xmlChar *tmp;
   
                       if ((max > XML_MAX_NAME_LENGTH) &&
                           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
                           xmlFree(buffer);
                           return(NULL);
                       }
                     max *= 2;                      max *= 2;
                     tmp = (xmlChar *) xmlRealloc(buffer,                      tmp = (xmlChar *) xmlRealloc(buffer,
                                                     max * sizeof(xmlChar));                                                      max * sizeof(xmlChar));
Line 3604  xmlParseNmtoken(xmlParserCtxtPtr ctxt) { Line 3740  xmlParseNmtoken(xmlParserCtxtPtr ctxt) {
     }      }
     if (len == 0)      if (len == 0)
         return(NULL);          return(NULL);
       if ((len > XML_MAX_NAME_LENGTH) &&
           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
           xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NmToken");
           return(NULL);
       }
     return(xmlStrndup(buf, len));      return(xmlStrndup(buf, len));
 }  }
   
Line 3650  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o Line 3791  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o
     ctxt->instate = XML_PARSER_ENTITY_VALUE;      ctxt->instate = XML_PARSER_ENTITY_VALUE;
     input = ctxt->input;      input = ctxt->input;
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF) {
           xmlFree(buf);
           return(NULL);
       }
     NEXT;      NEXT;
     c = CUR_CHAR(l);      c = CUR_CHAR(l);
     /*      /*
Line 3657  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o Line 3802  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o
      * When a parameter entity reference appears in a literal entity       * When a parameter entity reference appears in a literal entity
      * value, ... a single or double quote character in the replacement       * value, ... a single or double quote character in the replacement
      * text is always treated as a normal data character and will not       * text is always treated as a normal data character and will not
     * terminate the literal.      * terminate the literal.
      * In practice it means we stop the loop only when back at parsing       * In practice it means we stop the loop only when back at parsing
      * the initial entity and the quote is found       * the initial entity and the quote is found
      */       */
    while ((IS_CHAR(c)) && ((c != stop) || /* checked */    while (((IS_CHAR(c)) && ((c != stop) || /* checked */
           (ctxt->input != input))) {            (ctxt->input != input))) && (ctxt->instate != XML_PARSER_EOF)) {
         if (len + 5 >= size) {          if (len + 5 >= size) {
             xmlChar *tmp;              xmlChar *tmp;
   
Line 3691  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o Line 3836  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o
         }          }
     }      }
     buf[len] = 0;      buf[len] = 0;
       if (ctxt->instate == XML_PARSER_EOF) {
           xmlFree(buf);
           return(NULL);
       }
   
     /*      /*
      * Raise problem w.r.t. '&' and '%' being used in non-entities       * Raise problem w.r.t. '&' and '%' being used in non-entities
Line 3738  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o Line 3887  xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **o
          */           */
         ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF,          ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF,
                                       0, 0, 0);                                        0, 0, 0);
        if (orig != NULL)         if (orig != NULL)
             *orig = buf;              *orig = buf;
         else          else
             xmlFree(buf);              xmlFree(buf);
     }      }
    
     return(ret);      return(ret);
 }  }
   
Line 3764  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3913  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
     xmlChar limit = 0;      xmlChar limit = 0;
     xmlChar *buf = NULL;      xmlChar *buf = NULL;
     xmlChar *rep = NULL;      xmlChar *rep = NULL;
    int len = 0;    size_t len = 0;
    int buf_size = 0;    size_t buf_size = 0;
     int c, l, in_space = 0;      int c, l, in_space = 0;
     xmlChar *current = NULL;      xmlChar *current = NULL;
     xmlEntityPtr ent;      xmlEntityPtr ent;
Line 3787  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3936  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
      * allocate a translation buffer.       * allocate a translation buffer.
      */       */
     buf_size = XML_PARSER_BUFFER_SIZE;      buf_size = XML_PARSER_BUFFER_SIZE;
    buf = (xmlChar *) xmlMallocAtomic(buf_size * sizeof(xmlChar));    buf = (xmlChar *) xmlMallocAtomic(buf_size);
     if (buf == NULL) goto mem_error;      if (buf == NULL) goto mem_error;
   
     /*      /*
      * OK loop until we reach one of the ending char or a size limit.       * OK loop until we reach one of the ending char or a size limit.
      */       */
     c = CUR_CHAR(l);      c = CUR_CHAR(l);
    while ((NXT(0) != limit) && /* checked */    while (((NXT(0) != limit) && /* checked */
           (IS_CHAR(c)) && (c != '<')) {            (IS_CHAR(c)) && (c != '<')) &&
             (ctxt->instate != XML_PARSER_EOF)) {
         /*
          * Impose a reasonable limit on attribute size, unless XML_PARSE_HUGE
          * special option is given
          */
         if ((len > XML_MAX_TEXT_LENGTH) &&
             ((ctxt->options & XML_PARSE_HUGE) == 0)) {
             xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                            "AttValue length too long\n");
             goto mem_error;
         }
         if (c == 0) break;          if (c == 0) break;
         if (c == '&') {          if (c == '&') {
             in_space = 0;              in_space = 0;
Line 3804  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3964  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
   
                 if (val == '&') {                  if (val == '&') {
                     if (ctxt->replaceEntities) {                      if (ctxt->replaceEntities) {
                        if (len > buf_size - 10) {                        if (len + 10 > buf_size) {
                             growBuffer(buf, 10);                              growBuffer(buf, 10);
                         }                          }
                         buf[len++] = '&';                          buf[len++] = '&';
Line 3813  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3973  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                          * The reparsing will be done in xmlStringGetNodeList()                           * The reparsing will be done in xmlStringGetNodeList()
                          * called by the attribute() function in SAX.c                           * called by the attribute() function in SAX.c
                          */                           */
                        if (len > buf_size - 10) {                        if (len + 10 > buf_size) {
                             growBuffer(buf, 10);                              growBuffer(buf, 10);
                         }                          }
                         buf[len++] = '&';                          buf[len++] = '&';
Line 3823  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3983  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                         buf[len++] = ';';                          buf[len++] = ';';
                     }                      }
                 } else if (val != 0) {                  } else if (val != 0) {
                    if (len > buf_size - 10) {                    if (len + 10 > buf_size) {
                         growBuffer(buf, 10);                          growBuffer(buf, 10);
                     }                      }
                     len += xmlCopyChar(0, &buf[len], val);                      len += xmlCopyChar(0, &buf[len], val);
Line 3835  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 3995  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                     ctxt->nbentities += ent->owner;                      ctxt->nbentities += ent->owner;
                 if ((ent != NULL) &&                  if ((ent != NULL) &&
                     (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {                      (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) {
                    if (len > buf_size - 10) {                    if (len + 10 > buf_size) {
                         growBuffer(buf, 10);                          growBuffer(buf, 10);
                     }                      }
                     if ((ctxt->replaceEntities == 0) &&                      if ((ctxt->replaceEntities == 0) &&
Line 3848  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4008  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                     } else {                      } else {
                         buf[len++] = ent->content[0];                          buf[len++] = ent->content[0];
                     }                      }
                } else if ((ent != NULL) &&                 } else if ((ent != NULL) &&
                            (ctxt->replaceEntities != 0)) {                             (ctxt->replaceEntities != 0)) {
                     if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) {                      if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) {
                         rep = xmlStringDecodeEntities(ctxt, ent->content,                          rep = xmlStringDecodeEntities(ctxt, ent->content,
Line 3863  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4023  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                                     current++;                                      current++;
                                 } else                                  } else
                                     buf[len++] = *current++;                                      buf[len++] = *current++;
                                if (len > buf_size - 10) {                                if (len + 10 > buf_size) {
                                     growBuffer(buf, 10);                                      growBuffer(buf, 10);
                                 }                                  }
                             }                              }
Line 3871  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4031  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                             rep = NULL;                              rep = NULL;
                         }                          }
                     } else {                      } else {
                        if (len > buf_size - 10) {                        if (len + 10 > buf_size) {
                             growBuffer(buf, 10);                              growBuffer(buf, 10);
                         }                          }
                         if (ent->content != NULL)                          if (ent->content != NULL)
Line 3886  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4046  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                      * entities problems                       * entities problems
                      */                       */
                     if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&                      if ((ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
                        (ent->content != NULL)) {                        (ent->content != NULL) && (ent->checked == 0)) {
                         unsigned long oldnbent = ctxt->nbentities;
 
                         rep = xmlStringDecodeEntities(ctxt, ent->content,                          rep = xmlStringDecodeEntities(ctxt, ent->content,
                                                   XML_SUBSTITUTE_REF, 0, 0, 0);                                                    XML_SUBSTITUTE_REF, 0, 0, 0);
   
                           ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
                         if (rep != NULL) {                          if (rep != NULL) {
                               if (xmlStrchr(rep, '<'))
                                   ent->checked |= 1;
                             xmlFree(rep);                              xmlFree(rep);
                             rep = NULL;                              rep = NULL;
                         }                          }
Line 3899  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4065  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                      * Just output the reference                       * Just output the reference
                      */                       */
                     buf[len++] = '&';                      buf[len++] = '&';
                    while (len > buf_size - i - 10) {                    while (len + i + 10 > buf_size) {
                         growBuffer(buf, i + 10);                          growBuffer(buf, i + 10);
                     }                      }
                     for (;i > 0;i--)                      for (;i > 0;i--)
Line 3912  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4078  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
                 if ((len != 0) || (!normalize)) {                  if ((len != 0) || (!normalize)) {
                     if ((!normalize) || (!in_space)) {                      if ((!normalize) || (!in_space)) {
                         COPY_BUF(l,buf,len,0x20);                          COPY_BUF(l,buf,len,0x20);
                        while (len > buf_size - 10) {                        while (len + 10 > buf_size) {
                             growBuffer(buf, 10);                              growBuffer(buf, 10);
                         }                          }
                     }                      }
Line 3921  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4087  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
             } else {              } else {
                 in_space = 0;                  in_space = 0;
                 COPY_BUF(l,buf,len,c);                  COPY_BUF(l,buf,len,c);
                if (len > buf_size - 10) {                if (len + 10 > buf_size) {
                     growBuffer(buf, 10);                      growBuffer(buf, 10);
                 }                  }
             }              }
Line 3930  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4096  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
         GROW;          GROW;
         c = CUR_CHAR(l);          c = CUR_CHAR(l);
     }      }
       if (ctxt->instate == XML_PARSER_EOF)
           goto error;
   
     if ((in_space) && (normalize)) {      if ((in_space) && (normalize)) {
        while (buf[len - 1] == 0x20) len--;        while ((len > 0) && (buf[len - 1] == 0x20)) len--;
     }      }
     buf[len] = 0;      buf[len] = 0;
     if (RAW == '<') {      if (RAW == '<') {
Line 3946  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at Line 4115  xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *at
         }          }
     } else      } else
         NEXT;          NEXT;
    if (attlen != NULL) *attlen = len;
     /*
      * There we potentially risk an overflow, don't allow attribute value of
      * length more than INT_MAX it is a very reasonnable assumption !
      */
     if (len >= INT_MAX) {
         xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                        "AttValue length too long\n");
         goto mem_error;
     }
 
     if (attlen != NULL) *attlen = (int) len;
     return(buf);      return(buf);
   
 mem_error:  mem_error:
     xmlErrMemory(ctxt, NULL);      xmlErrMemory(ctxt, NULL);
   error:
     if (buf != NULL)      if (buf != NULL)
         xmlFree(buf);          xmlFree(buf);
     if (rep != NULL)      if (rep != NULL)
Line 3971  mem_error: Line 4152  mem_error:
  *   *
  * 3.3.3 Attribute-Value Normalization:   * 3.3.3 Attribute-Value Normalization:
  * Before the value of an attribute is passed to the application or   * Before the value of an attribute is passed to the application or
 * checked for validity, the XML processor must normalize it as follows:  * checked for validity, the XML processor must normalize it as follows:
  * - a character reference is processed by appending the referenced   * - a character reference is processed by appending the referenced
  *   character to the attribute value   *   character to the attribute value
  * - an entity reference is processed by recursively processing the   * - an entity reference is processed by recursively processing the
 *   replacement text of the entity  *   replacement text of the entity
  * - a whitespace character (#x20, #xD, #xA, #x9) is processed by   * - a whitespace character (#x20, #xD, #xA, #x9) is processed by
  *   appending #x20 to the normalized value, except that only a single   *   appending #x20 to the normalized value, except that only a single
  *   #x20 is appended for a "#xD#xA" sequence that is part of an external   *   #x20 is appended for a "#xD#xA" sequence that is part of an external
 *   parsed entity or the literal entity value of an internal parsed entity  *   parsed entity or the literal entity value of an internal parsed entity
 * - other characters are processed by appending them to the normalized value  * - other characters are processed by appending them to the normalized value
  * If the declared value is not CDATA, then the XML processor must further   * If the declared value is not CDATA, then the XML processor must further
  * process the normalized attribute value by discarding any leading and   * process the normalized attribute value by discarding any leading and
  * trailing space (#x20) characters, and by replacing sequences of space   * trailing space (#x20) characters, and by replacing sequences of space
 * (#x20) characters by a single space (#x20) character.   * (#x20) characters by a single space (#x20) character.
  * All attributes for which no declaration has been read should be treated   * All attributes for which no declaration has been read should be treated
  * by a non-validating parser as if declared CDATA.   * by a non-validating parser as if declared CDATA.
  *   *
Line 4001  xmlParseAttValue(xmlParserCtxtPtr ctxt) { Line 4182  xmlParseAttValue(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseSystemLiteral:   * xmlParseSystemLiteral:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse an XML Literal   * parse an XML Literal
  *   *
  * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")   * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
Line 4030  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { Line 4211  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) {
         xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL);          xmlFatalErr(ctxt, XML_ERR_LITERAL_NOT_STARTED, NULL);
         return(NULL);          return(NULL);
     }      }
    
     buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));      buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
     if (buf == NULL) {      if (buf == NULL) {
         xmlErrMemory(ctxt, NULL);          xmlErrMemory(ctxt, NULL);
Line 4042  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { Line 4223  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) {
         if (len + 5 >= size) {          if (len + 5 >= size) {
             xmlChar *tmp;              xmlChar *tmp;
   
               if ((size > XML_MAX_NAME_LENGTH) &&
                   ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                   xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "SystemLiteral");
                   xmlFree(buf);
                   ctxt->instate = (xmlParserInputState) state;
                   return(NULL);
               }
             size *= 2;              size *= 2;
             tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));              tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
             if (tmp == NULL) {              if (tmp == NULL) {
Line 4056  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) { Line 4244  xmlParseSystemLiteral(xmlParserCtxtPtr ctxt) {
         if (count > 50) {          if (count > 50) {
             GROW;              GROW;
             count = 0;              count = 0;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlFree(buf);
                   return(NULL);
               }
         }          }
         COPY_BUF(l,buf,len,cur);          COPY_BUF(l,buf,len,cur);
         NEXTL(l);          NEXTL(l);
Line 4119  xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { Line 4311  xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) {
         if (len + 1 >= size) {          if (len + 1 >= size) {
             xmlChar *tmp;              xmlChar *tmp;
   
               if ((size > XML_MAX_NAME_LENGTH) &&
                   ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                   xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Public ID");
                   xmlFree(buf);
                   return(NULL);
               }
             size *= 2;              size *= 2;
             tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));              tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
             if (tmp == NULL) {              if (tmp == NULL) {
Line 4133  xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) { Line 4331  xmlParsePubidLiteral(xmlParserCtxtPtr ctxt) {
         if (count > 50) {          if (count > 50) {
             GROW;              GROW;
             count = 0;              count = 0;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlFree(buf);
                   return(NULL);
               }
         }          }
         NEXT;          NEXT;
         cur = CUR;          cur = CUR;
Line 4203  static const unsigned char test_char_data[256] = { Line 4405  static const unsigned char test_char_data[256] = {
  * The right angle bracket (>) may be represented using the string "&gt;",   * The right angle bracket (>) may be represented using the string "&gt;",
  * and must, for compatibility, be escaped using "&gt;" or a character   * and must, for compatibility, be escaped using "&gt;" or a character
  * reference when it appears in the string "]]>" in content, when that   * reference when it appears in the string "]]>" in content, when that
 * string is not marking the end of a CDATA section.  * string is not marking the end of a CDATA section.
  *   *
  * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)   * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
  */   */
Line 4339  get_more: Line 4541  get_more:
             }              }
             SHRINK;              SHRINK;
             GROW;              GROW;
               if (ctxt->instate == XML_PARSER_EOF)
                   return;
             in = ctxt->input->cur;              in = ctxt->input->cur;
         } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09));          } while (((*in >= 0x20) && (*in <= 0x7F)) || (*in == 0x09));
         nbchar = 0;          nbchar = 0;
Line 4368  xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cda Line 4572  xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cda
     GROW;      GROW;
     cur = CUR_CHAR(l);      cur = CUR_CHAR(l);
     while ((cur != '<') && /* checked */      while ((cur != '<') && /* checked */
           (cur != '&') &&            (cur != '&') &&
            (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ {             (IS_CHAR(cur))) /* test also done in xmlCurrentChar() */ {
         if ((cur == ']') && (NXT(1) == ']') &&          if ((cur == ']') && (NXT(1) == ']') &&
             (NXT(2) == '>')) {              (NXT(2) == '>')) {
Line 4407  xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cda Line 4611  xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int cda
         if (count > 50) {          if (count > 50) {
             GROW;              GROW;
             count = 0;              count = 0;
               if (ctxt->instate == XML_PARSER_EOF)
                   return;
         }          }
         NEXTL(l);          NEXTL(l);
         cur = CUR_CHAR(l);          cur = CUR_CHAR(l);
Line 4499  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu Line 4705  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu
             }              }
         } else {          } else {
             /*              /*
             * We handle [83] so we return immediately, if              * We handle [83] so we return immediately, if
              * "S SystemLiteral" is not detected. From a purely parsing               * "S SystemLiteral" is not detected. From a purely parsing
              * point of view that's a nice mess.               * point of view that's a nice mess.
              */               */
Line 4508  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu Line 4714  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu
   
             ptr = CUR_PTR;              ptr = CUR_PTR;
             if (!IS_BLANK_CH(*ptr)) return(NULL);              if (!IS_BLANK_CH(*ptr)) return(NULL);
            
             while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */              while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */
             if ((*ptr != '\'') && (*ptr != '"')) return(NULL);              if ((*ptr != '\'') && (*ptr != '"')) return(NULL);
         }          }
Line 4536  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu Line 4742  xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **pu
  * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'   * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
  */   */
 static void  static void
xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf, int len, int size) {xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf,
                        size_t len, size_t size) {
     int q, ql;      int q, ql;
     int r, rl;      int r, rl;
     int cur, l;      int cur, l;
    int count = 0;    size_t count = 0;
     int inputid;      int inputid;
   
     inputid = ctxt->input->id;      inputid = ctxt->input->id;
Line 4586  xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar  Line 4793  xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar 
         if ((r == '-') && (q == '-')) {          if ((r == '-') && (q == '-')) {
             xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL);              xmlFatalErr(ctxt, XML_ERR_HYPHEN_IN_COMMENT, NULL);
         }          }
           if ((len > XML_MAX_TEXT_LENGTH) &&
               ((ctxt->options & XML_PARSE_HUGE) == 0)) {
               xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
                            "Comment too big found", NULL);
               xmlFree (buf);
               return;
           }
         if (len + 5 >= size) {          if (len + 5 >= size) {
             xmlChar *new_buf;              xmlChar *new_buf;
            size *= 2;            size_t new_size;
            new_buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
             new_size = size * 2;
             new_buf = (xmlChar *) xmlRealloc(buf, new_size);
             if (new_buf == NULL) {              if (new_buf == NULL) {
                 xmlFree (buf);                  xmlFree (buf);
                 xmlErrMemory(ctxt, NULL);                  xmlErrMemory(ctxt, NULL);
                 return;                  return;
             }              }
             buf = new_buf;              buf = new_buf;
               size = new_size;
         }          }
         COPY_BUF(ql,buf,len,q);          COPY_BUF(ql,buf,len,q);
         q = r;          q = r;
Line 4607  xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar  Line 4824  xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar 
         if (count > 50) {          if (count > 50) {
             GROW;              GROW;
             count = 0;              count = 0;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlFree(buf);
                   return;
               }
         }          }
         NEXTL(l);          NEXTL(l);
         cur = CUR_CHAR(l);          cur = CUR_CHAR(l);
Line 4656  not_terminated: Line 4877  not_terminated:
 void  void
 xmlParseComment(xmlParserCtxtPtr ctxt) {  xmlParseComment(xmlParserCtxtPtr ctxt) {
     xmlChar *buf = NULL;      xmlChar *buf = NULL;
    int size = XML_PARSER_BUFFER_SIZE;    size_t size = XML_PARSER_BUFFER_SIZE;
    int len = 0;    size_t len = 0;
     xmlParserInputState state;      xmlParserInputState state;
     const xmlChar *in;      const xmlChar *in;
    int nbchar = 0, ccol;    size_t nbchar = 0;
     int ccol;
     int inputid;      int inputid;
   
     /*      /*
Line 4740  get_more: Line 4962  get_more:
                 buf[len] = 0;                  buf[len] = 0;
             }              }
         }          }
           if ((len > XML_MAX_TEXT_LENGTH) &&
               ((ctxt->options & XML_PARSE_HUGE) == 0)) {
               xmlFatalErrMsgStr(ctxt, XML_ERR_COMMENT_NOT_FINISHED,
                            "Comment too big found", NULL);
               xmlFree (buf);
               return;
           }
         ctxt->input->cur = in;          ctxt->input->cur = in;
         if (*in == 0xA) {          if (*in == 0xA) {
             in++;              in++;
Line 4757  get_more: Line 4986  get_more:
         }          }
         SHRINK;          SHRINK;
         GROW;          GROW;
           if (ctxt->instate == XML_PARSER_EOF) {
               xmlFree(buf);
               return;
           }
         in = ctxt->input->cur;          in = ctxt->input->cur;
         if (*in == '-') {          if (*in == '-') {
             if (in[1] == '-') {              if (in[1] == '-') {
Line 4775  get_more: Line 5008  get_more:
                     }                      }
                     if (buf != NULL)                      if (buf != NULL)
                         xmlFree(buf);                          xmlFree(buf);
                    ctxt->instate = state;                    if (ctxt->instate != XML_PARSER_EOF)
                         ctxt->instate = state;
                     return;                      return;
                 }                  }
                 if (buf != NULL) {                  if (buf != NULL) {
Line 4803  get_more: Line 5037  get_more:
 /**  /**
  * xmlParsePITarget:   * xmlParsePITarget:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse the name of a PI   * parse the name of a PI
  *   *
  * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))   * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
Line 4840  xmlParsePITarget(xmlParserCtxtPtr ctxt) { Line 5074  xmlParsePITarget(xmlParserCtxtPtr ctxt) {
                       NULL, NULL);                        NULL, NULL);
     }      }
     if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) {      if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) {
        xmlNsErr(ctxt, XML_NS_ERR_COLON,         xmlNsErr(ctxt, XML_NS_ERR_COLON,
                  "colon are forbidden from PI names '%s'\n", name, NULL, NULL);                   "colon are forbidden from PI names '%s'\n", name, NULL, NULL);
     }      }
     return(name);      return(name);
Line 4851  xmlParsePITarget(xmlParserCtxtPtr ctxt) { Line 5085  xmlParsePITarget(xmlParserCtxtPtr ctxt) {
  * xmlParseCatalogPI:   * xmlParseCatalogPI:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
  * @catalog:  the PI value string   * @catalog:  the PI value string
 *  *
  * parse an XML Catalog Processing Instruction.   * parse an XML Catalog Processing Instruction.
  *   *
  * <?oasis-xml-catalog catalog="http://example.com/catalog.xml"?>   * <?oasis-xml-catalog catalog="http://example.com/catalog.xml"?>
Line 4911  error: Line 5145  error:
 /**  /**
  * xmlParsePI:   * xmlParsePI:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse an XML Processing Instruction.   * parse an XML Processing Instruction.
  *   *
  * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'   * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
Line 4922  error: Line 5156  error:
 void  void
 xmlParsePI(xmlParserCtxtPtr ctxt) {  xmlParsePI(xmlParserCtxtPtr ctxt) {
     xmlChar *buf = NULL;      xmlChar *buf = NULL;
    int len = 0;    size_t len = 0;
    int size = XML_PARSER_BUFFER_SIZE;    size_t size = XML_PARSER_BUFFER_SIZE;
     int cur, l;      int cur, l;
     const xmlChar *target;      const xmlChar *target;
     xmlParserInputState state;      xmlParserInputState state;
Line 4980  xmlParsePI(xmlParserCtxtPtr ctxt) { Line 5214  xmlParsePI(xmlParserCtxtPtr ctxt) {
                    ((cur != '?') || (NXT(1) != '>'))) {                     ((cur != '?') || (NXT(1) != '>'))) {
                 if (len + 5 >= size) {                  if (len + 5 >= size) {
                     xmlChar *tmp;                      xmlChar *tmp;
                    size_t new_size = size * 2;
                    size *= 2;                    tmp = (xmlChar *) xmlRealloc(buf, new_size);
                    tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); 
                     if (tmp == NULL) {                      if (tmp == NULL) {
                         xmlErrMemory(ctxt, NULL);                          xmlErrMemory(ctxt, NULL);
                         xmlFree(buf);                          xmlFree(buf);
Line 4990  xmlParsePI(xmlParserCtxtPtr ctxt) { Line 5223  xmlParsePI(xmlParserCtxtPtr ctxt) {
                         return;                          return;
                     }                      }
                     buf = tmp;                      buf = tmp;
                       size = new_size;
                 }                  }
                 count++;                  count++;
                 if (count > 50) {                  if (count > 50) {
                     GROW;                      GROW;
                       if (ctxt->instate == XML_PARSER_EOF) {
                           xmlFree(buf);
                           return;
                       }
                     count = 0;                      count = 0;
                       if ((len > XML_MAX_TEXT_LENGTH) &&
                           ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                           xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
                                             "PI %s too big found", target);
                           xmlFree(buf);
                           ctxt->instate = state;
                           return;
                       }
                 }                  }
                 COPY_BUF(l,buf,len,cur);                  COPY_BUF(l,buf,len,cur);
                 NEXTL(l);                  NEXTL(l);
Line 5005  xmlParsePI(xmlParserCtxtPtr ctxt) { Line 5251  xmlParsePI(xmlParserCtxtPtr ctxt) {
                     cur = CUR_CHAR(l);                      cur = CUR_CHAR(l);
                 }                  }
             }              }
               if ((len > XML_MAX_TEXT_LENGTH) &&
                   ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                   xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
                                     "PI %s too big found", target);
                   xmlFree(buf);
                   ctxt->instate = state;
                   return;
               }
             buf[len] = 0;              buf[len] = 0;
             if (cur != '?') {              if (cur != '?') {
                 xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,                  xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
Line 5066  xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { Line 5320  xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
     const xmlChar *name;      const xmlChar *name;
     xmlChar *Pubid;      xmlChar *Pubid;
     xmlChar *Systemid;      xmlChar *Systemid;
    
     if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) {      if (CMP10(CUR_PTR, '<', '!', 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N')) {
         xmlParserInputPtr input = ctxt->input;          xmlParserInputPtr input = ctxt->input;
         SHRINK;          SHRINK;
Line 5089  xmlParseNotationDecl(xmlParserCtxtPtr ctxt) { Line 5343  xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
             return;              return;
         }          }
         if (xmlStrchr(name, ':') != NULL) {          if (xmlStrchr(name, ':') != NULL) {
            xmlNsErr(ctxt, XML_NS_ERR_COLON,             xmlNsErr(ctxt, XML_NS_ERR_COLON,
                      "colon are forbidden from notation names '%s'\n",                       "colon are forbidden from notation names '%s'\n",
                      name, NULL, NULL);                       name, NULL, NULL);
         }          }
Line 5149  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { Line 5403  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
     int isParameter = 0;      int isParameter = 0;
     xmlChar *orig = NULL;      xmlChar *orig = NULL;
     int skipped;      int skipped;
    
     /* GROW; done in the caller */      /* GROW; done in the caller */
     if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) {      if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T', 'I', 'T', 'Y')) {
         xmlParserInputPtr input = ctxt->input;          xmlParserInputPtr input = ctxt->input;
Line 5178  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { Line 5432  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
             return;              return;
         }          }
         if (xmlStrchr(name, ':') != NULL) {          if (xmlStrchr(name, ':') != NULL) {
            xmlNsErr(ctxt, XML_NS_ERR_COLON,             xmlNsErr(ctxt, XML_NS_ERR_COLON,
                      "colon are forbidden from entities names '%s'\n",                       "colon are forbidden from entities names '%s'\n",
                      name, NULL, NULL);                       name, NULL, NULL);
         }          }
Line 5343  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { Line 5597  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
                 }                  }
             }              }
         }          }
           if (ctxt->instate == XML_PARSER_EOF)
               return;
         SKIP_BLANKS;          SKIP_BLANKS;
         if (RAW != '>') {          if (RAW != '>') {
             xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,              xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
Line 5406  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) { Line 5662  xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
  *   *
  * [ VC: Fixed Attribute Default ]   * [ VC: Fixed Attribute Default ]
  * if an attribute has a default value declared with the #FIXED   * if an attribute has a default value declared with the #FIXED
 * keyword, instances of that attribute must match the default value.  * keyword, instances of that attribute must match the default value.
  *   *
  * [ WFC: No < in Attribute Values ]   * [ WFC: No < in Attribute Values ]
  * handled in xmlParseAttValue()   * handled in xmlParseAttValue()
  *   *
  * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED   * returns: XML_ATTRIBUTE_NONE, XML_ATTRIBUTE_REQUIRED, XML_ATTRIBUTE_IMPLIED
 *          or XML_ATTRIBUTE_FIXED.  *          or XML_ATTRIBUTE_FIXED.
  */   */
   
 int  int
Line 5461  xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **v Line 5717  xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **v
  *   *
  * [ VC: Notation Attributes ]   * [ VC: Notation Attributes ]
  * Values of this type must match one of the notation names included   * Values of this type must match one of the notation names included
 * in the declaration; all notation names in the declaration must be declared.  * in the declaration; all notation names in the declaration must be declared.
  *   *
  * Returns: the notation attribute tree built while parsing   * Returns: the notation attribute tree built while parsing
  */   */
Line 5661  xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnume Line 5917  xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnume
  * [ VC: Entity Name ]   * [ VC: Entity Name ]
  * Values of type ENTITY must match the Name production, values   * Values of type ENTITY must match the Name production, values
  * of type ENTITIES must match Names; each Entity Name must match the   * of type ENTITIES must match Names; each Entity Name must match the
 * name of an unparsed entity declared in the DTD.   * name of an unparsed entity declared in the DTD.
  *   *
  * [ VC: Name Token ]   * [ VC: Name Token ]
  * Values of type NMTOKEN must match the Nmtoken production; values   * Values of type NMTOKEN must match the Nmtoken production; values
 * of type NMTOKENS must match Nmtokens.  * of type NMTOKENS must match Nmtokens.
  *   *
  * Returns the attribute type   * Returns the attribute type
  */   */
int int
 xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {  xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
     SHRINK;      SHRINK;
     if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) {      if (CMP5(CUR_PTR, 'C', 'D', 'A', 'T', 'A')) {
Line 5734  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { Line 5990  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
         }          }
         SKIP_BLANKS;          SKIP_BLANKS;
         GROW;          GROW;
        while (RAW != '>') {        while ((RAW != '>') && (ctxt->instate != XML_PARSER_EOF)) {
             const xmlChar *check = CUR_PTR;              const xmlChar *check = CUR_PTR;
             int type;              int type;
             int def;              int def;
Line 5812  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { Line 6068  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
                 xmlFreeEnumeration(tree);                  xmlFreeEnumeration(tree);
   
             if ((ctxt->sax2) && (defaultValue != NULL) &&              if ((ctxt->sax2) && (defaultValue != NULL) &&
                (def != XML_ATTRIBUTE_IMPLIED) &&                 (def != XML_ATTRIBUTE_IMPLIED) &&
                 (def != XML_ATTRIBUTE_REQUIRED)) {                  (def != XML_ATTRIBUTE_REQUIRED)) {
                 xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue);                  xmlAddDefAttrs(ctxt, elemName, attrName, defaultValue);
             }              }
Line 5841  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { Line 6097  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
  *   *
  * parse the declaration for a Mixed Element content   * parse the declaration for a Mixed Element content
  * The leading '(' and spaces have been skipped in xmlParseElementContentDecl   * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
 *  *
  * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' |   * [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' |
  *                '(' S? '#PCDATA' S? ')'   *                '(' S? '#PCDATA' S? ')'
  *   *
Line 5849  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) { Line 6105  xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
  *   *
  * [ VC: No Duplicate Types ]   * [ VC: No Duplicate Types ]
  * The same name must not appear more than once in a single   * The same name must not appear more than once in a single
 * mixed-content declaration.  * mixed-content declaration.
  *   *
  * returns: the list of the xmlElementContentPtr describing the element choices   * returns: the list of the xmlElementContentPtr describing the element choices
  */   */
Line 5883  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, Line 6139  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt,
             ret = cur = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA);              ret = cur = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA);
             if (ret == NULL) return(NULL);              if (ret == NULL) return(NULL);
         }          }
        while (RAW == '|') {        while ((RAW == '|') && (ctxt->instate != XML_PARSER_EOF)) {
             NEXT;              NEXT;
             if (elem == NULL) {              if (elem == NULL) {
                 ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_OR);                  ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_OR);
Line 5949  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, Line 6205  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt,
  *   *
  * parse the declaration for a Mixed Element content   * parse the declaration for a Mixed Element content
  * The leading '(' and spaces have been skipped in xmlParseElementContentDecl   * The leading '(' and spaces have been skipped in xmlParseElementContentDecl
  *   
  *   *
    *
  * [47] children ::= (choice | seq) ('?' | '*' | '+')?   * [47] children ::= (choice | seq) ('?' | '*' | '+')?
  *   *
  * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?   * [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
Line 5970  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, Line 6226  xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt,
  *      be empty, and neither the first nor last non-blank character of   *      be empty, and neither the first nor last non-blank character of
  *      the replacement text should be a connector (| or ,).   *      the replacement text should be a connector (| or ,).
  *   *
 * Returns the tree of xmlElementContentPtr describing the element  * Returns the tree of xmlElementContentPtr describing the element
  *          hierarchy.   *          hierarchy.
  */   */
 static xmlElementContentPtr  static xmlElementContentPtr
Line 6027  xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPt Line 6283  xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPt
     }      }
     SKIP_BLANKS;      SKIP_BLANKS;
     SHRINK;      SHRINK;
    while (RAW != ')') {    while ((RAW != ')') && (ctxt->instate != XML_PARSER_EOF)) {
         /*          /*
          * Each loop we parse one separator and one element.           * Each loop we parse one separator and one element.
          */           */
Line 6283  xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ct Line 6539  xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ct
  *   *
  * parse the declaration for an Element content either Mixed or Children,   * parse the declaration for an Element content either Mixed or Children,
  * the cases EMPTY and ANY are handled directly in xmlParseElementDecl   * the cases EMPTY and ANY are handled directly in xmlParseElementDecl
 *  *
  * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children   * [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
  *   *
  * returns: the type of element content XML_ELEMENT_TYPE_xxx   * returns: the type of element content XML_ELEMENT_TYPE_xxx
Line 6306  xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, cons Line 6562  xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, cons
     }      }
     NEXT;      NEXT;
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
     SKIP_BLANKS;      SKIP_BLANKS;
     if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {      if (CMP7(CUR_PTR, '#', 'P', 'C', 'D', 'A', 'T', 'A')) {
         tree = xmlParseElementMixedContentDecl(ctxt, inputid);          tree = xmlParseElementMixedContentDecl(ctxt, inputid);
Line 6409  xmlParseElementDecl(xmlParserCtxtPtr ctxt) { Line 6667  xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
                 xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,                  xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
     "Element declaration doesn't start and stop in the same entity\n");      "Element declaration doesn't start and stop in the same entity\n");
             }              }
                
             NEXT;              NEXT;
             if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&              if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
                 (ctxt->sax->elementDecl != NULL)) {                  (ctxt->sax->elementDecl != NULL)) {
Line 6421  xmlParseElementDecl(xmlParserCtxtPtr ctxt) { Line 6679  xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
                     /*                      /*
                      * this is a trick: if xmlAddElementDecl is called,                       * this is a trick: if xmlAddElementDecl is called,
                      * instead of copying the full tree it is plugged directly                       * instead of copying the full tree it is plugged directly
                     * if called from the parser. Avoid duplicating the                      * if called from the parser. Avoid duplicating the
                      * interfaces or change the API/ABI                       * interfaces or change the API/ABI
                      */                       */
                     xmlFreeDocElementContent(ctxt->myDoc, content);                      xmlFreeDocElementContent(ctxt->myDoc, content);
Line 6438  xmlParseElementDecl(xmlParserCtxtPtr ctxt) { Line 6696  xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
  * xmlParseConditionalSections   * xmlParseConditionalSections
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
  *   *
 * [61] conditionalSect ::= includeSect | ignoreSect  * [61] conditionalSect ::= includeSect | ignoreSect
 * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'  * [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
  * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'   * [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
  * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*   * [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
  * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)   * [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
Line 6473  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { Line 6731  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
                     "Entering INCLUDE Conditional Section\n");                      "Entering INCLUDE Conditional Section\n");
         }          }
   
        while ((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') ||        while (((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') ||
               (NXT(2) != '>'))) {                (NXT(2) != '>'))) && (ctxt->instate != XML_PARSER_EOF)) {
             const xmlChar *check = CUR_PTR;              const xmlChar *check = CUR_PTR;
             unsigned int cons = ctxt->input->consumed;              unsigned int cons = ctxt->input->consumed;
   
Line 6542  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { Line 6800  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
         if (ctxt->recovery == 0) ctxt->disableSAX = 1;          if (ctxt->recovery == 0) ctxt->disableSAX = 1;
         ctxt->instate = XML_PARSER_IGNORE;          ctxt->instate = XML_PARSER_IGNORE;
   
        while ((depth >= 0) && (RAW != 0)) {        while (((depth >= 0) && (RAW != 0)) &&
                (ctxt->instate != XML_PARSER_EOF)) {
           if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {            if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) == '[')) {
             depth++;              depth++;
             SKIP(3);              SKIP(3);
Line 6590  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { Line 6849  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseMarkupDecl:   * xmlParseMarkupDecl:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse Markup declarations   * parse Markup declarations
  *   *
  * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |   * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
Line 6607  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) { Line 6866  xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
  * In the internal DTD subset, parameter-entity references can occur   * In the internal DTD subset, parameter-entity references can occur
  * only where markup declarations can occur, not within markup declarations.   * only where markup declarations can occur, not within markup declarations.
  * (This does not apply to references that occur in external parameter   * (This does not apply to references that occur in external parameter
 * entities or to the external subset.)  * entities or to the external subset.)
  */   */
 void  void
 xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {  xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
Line 6736  xmlParseTextDecl(xmlParserCtxtPtr ctxt) { Line 6995  xmlParseTextDecl(xmlParserCtxtPtr ctxt) {
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
  * @ExternalID: the external identifier   * @ExternalID: the external identifier
  * @SystemID: the system identifier (or URL)   * @SystemID: the system identifier (or URL)
 *  *
  * parse Markup declarations from an external subset   * parse Markup declarations from an external subset
  *   *
  * [30] extSubset ::= textDecl? extSubsetDecl   * [30] extSubset ::= textDecl? extSubsetDecl
Line 6813  xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xm Line 7072  xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xm
             break;              break;
         }          }
     }      }
    
     if (RAW != 0) {      if (RAW != 0) {
         xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);          xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
     }      }
Line 6915  xmlParseReference(xmlParserCtxtPtr ctxt) { Line 7174  xmlParseReference(xmlParserCtxtPtr ctxt) {
      * The first reference to the entity trigger a parsing phase       * The first reference to the entity trigger a parsing phase
      * where the ent->children is filled with the result from       * where the ent->children is filled with the result from
      * the parsing.       * the parsing.
        * Note: external parsed entities will not be loaded, it is not
        * required for a non-validating parser, unless the parsing option
        * of validating, or substituting entities were given. Doing so is
        * far more secure as the parser will only process data coming from
        * the document entity by default.
      */       */
    if (ent->checked == 0) {    if ((ent->checked == 0) &&
         ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||
          (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {
         unsigned long oldnbent = ctxt->nbentities;          unsigned long oldnbent = ctxt->nbentities;
   
         /*          /*
Line 6958  xmlParseReference(xmlParserCtxtPtr ctxt) { Line 7224  xmlParseReference(xmlParserCtxtPtr ctxt) {
          * Store the number of entities needing parsing for this entity           * Store the number of entities needing parsing for this entity
          * content and do checkings           * content and do checkings
          */           */
        ent->checked = ctxt->nbentities - oldnbent;        ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
         if ((ent->content != NULL) && (xmlStrchr(ent->content, '<')))
             ent->checked |= 1;
         if (ret == XML_ERR_ENTITY_LOOP) {          if (ret == XML_ERR_ENTITY_LOOP) {
             xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);              xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
             xmlFreeNodeList(list);              xmlFreeNodeList(list);
             return;              return;
         }          }
        if (xmlParserEntityCheck(ctxt, 0, ent)) {        if (xmlParserEntityCheck(ctxt, 0, ent, 0)) {
             xmlFreeNodeList(list);              xmlFreeNodeList(list);
             return;              return;
         }          }
Line 7023  xmlParseReference(xmlParserCtxtPtr ctxt) { Line 7291  xmlParseReference(xmlParserCtxtPtr ctxt) {
             list = NULL;              list = NULL;
         }          }
         if (ent->checked == 0)          if (ent->checked == 0)
            ent->checked = 1;            ent->checked = 2;
     } else if (ent->checked != 1) {      } else if (ent->checked != 1) {
        ctxt->nbentities += ent->checked;        ctxt->nbentities += ent->checked / 2;
     }      }
   
     /*      /*
Line 7116  xmlParseReference(xmlParserCtxtPtr ctxt) { Line 7384  xmlParseReference(xmlParserCtxtPtr ctxt) {
              * Seems we are generating the DOM content, do               * Seems we are generating the DOM content, do
              * a simple tree copy for all references except the first               * a simple tree copy for all references except the first
              * In the first occurrence list contains the replacement.               * In the first occurrence list contains the replacement.
              * progressive == 2 means we are operating on the Reader  
              * and since nodes are discarded we must copy all the time.  
              */               */
             if (((list == NULL) && (ent->owner == 0)) ||              if (((list == NULL) && (ent->owner == 0)) ||
                 (ctxt->parseMode == XML_PARSE_READER)) {                  (ctxt->parseMode == XML_PARSE_READER)) {
                 xmlNodePtr nw = NULL, cur, firstChild = NULL;                  xmlNodePtr nw = NULL, cur, firstChild = NULL;
   
                 /*                  /*
                    * We are copying here, make sure there is no abuse
                    */
                   ctxt->sizeentcopy += ent->length;
                   if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
                       return;
   
                   /*
                  * when operating on a reader, the entities definitions                   * when operating on a reader, the entities definitions
                  * are always owning the entities subtree.                   * are always owning the entities subtree.
                 if (ctxt->parseMode == XML_PARSE_READER)                  if (ctxt->parseMode == XML_PARSE_READER)
Line 7160  xmlParseReference(xmlParserCtxtPtr ctxt) { Line 7433  xmlParseReference(xmlParserCtxtPtr ctxt) {
                 if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)                  if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)
                   xmlAddEntityReference(ent, firstChild, nw);                    xmlAddEntityReference(ent, firstChild, nw);
 #endif /* LIBXML_LEGACY_ENABLED */  #endif /* LIBXML_LEGACY_ENABLED */
            } else if (list == NULL) {            } else if ((list == NULL) || (ctxt->inputNr > 0)) {
                 xmlNodePtr nw = NULL, cur, next, last,                  xmlNodePtr nw = NULL, cur, next, last,
                            firstChild = NULL;                             firstChild = NULL;
   
                 /*                  /*
                    * We are copying here, make sure there is no abuse
                    */
                   ctxt->sizeentcopy += ent->length;
                   if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
                       return;
   
                   /*
                  * Copy the entity child list and make it the new                   * Copy the entity child list and make it the new
                  * entity child list. The goal is to make sure any                   * entity child list. The goal is to make sure any
                  * ID or REF referenced will be the one from the                   * ID or REF referenced will be the one from the
Line 7260  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7541  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     xmlEntityPtr ent = NULL;      xmlEntityPtr ent = NULL;
   
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return(NULL);
   
     if (RAW != '&')      if (RAW != '&')
         return(NULL);          return(NULL);
Line 7277  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7560  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     NEXT;      NEXT;
   
     /*      /*
     * Predefined entites override any extra definition     * Predefined entities override any extra definition
      */       */
     if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {      if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
         ent = xmlGetPredefinedEntity(name);          ent = xmlGetPredefinedEntity(name);
Line 7286  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7569  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     }      }
   
     /*      /*
     * Increate the number of entity references parsed     * Increase the number of entity references parsed
      */       */
     ctxt->nbentities++;      ctxt->nbentities++;
   
Line 7297  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7580  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     if (ctxt->sax != NULL) {      if (ctxt->sax != NULL) {
         if (ctxt->sax->getEntity != NULL)          if (ctxt->sax->getEntity != NULL)
             ent = ctxt->sax->getEntity(ctxt->userData, name);              ent = ctxt->sax->getEntity(ctxt->userData, name);
        if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&         if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
             (ctxt->options & XML_PARSE_OLDSAX))              (ctxt->options & XML_PARSE_OLDSAX))
             ent = xmlGetPredefinedEntity(name);              ent = xmlGetPredefinedEntity(name);
         if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&          if ((ctxt->wellFormed == 1 ) && (ent == NULL) &&
Line 7305  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7588  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
             ent = xmlSAX2GetEntity(ctxt, name);              ent = xmlSAX2GetEntity(ctxt, name);
         }          }
     }      }
       if (ctxt->instate == XML_PARSER_EOF)
           return(NULL);
     /*      /*
      * [ WFC: Entity Declared ]       * [ WFC: Entity Declared ]
      * In a document without any DTD, a document with only an       * In a document without any DTD, a document with only an
Line 7368  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7653  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
      * [ WFC: No < in Attribute Values ]       * [ WFC: No < in Attribute Values ]
      * The replacement text of any entity referred to directly or       * The replacement text of any entity referred to directly or
      * indirectly in an attribute value (other than "&lt;") must       * indirectly in an attribute value (other than "&lt;") must
     * not contain a <.      * not contain a <.
      */       */
     else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&      else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
             (ent != NULL) && (ent->content != NULL) &&             (ent != NULL) && 
             (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&             (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) {
             (xmlStrchr(ent->content, '<'))) {        if ((ent->checked & 1) || ((ent->checked == 0) &&
        xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,             (ent->content != NULL) &&(xmlStrchr(ent->content, '<')))) {
    "'<' in entity '%s' is not allowed in attributes values\n", name);            xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
         "'<' in entity '%s' is not allowed in attributes values\n", name);
         }
     }      }
   
     /*      /*
Line 7397  xmlParseEntityRef(xmlParserCtxtPtr ctxt) { Line 7684  xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     /*      /*
      * [ WFC: No Recursion ]       * [ WFC: No Recursion ]
      * A parsed entity must not contain a recursive reference       * A parsed entity must not contain a recursive reference
     * to itself, either directly or indirectly.      * to itself, either directly or indirectly.
      * Done somewhere else       * Done somewhere else
      */       */
     return(ent);      return(ent);
Line 7495  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x Line 7782  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x
             ent = xmlSAX2GetEntity(ctxt, name);              ent = xmlSAX2GetEntity(ctxt, name);
         }          }
     }      }
       if (ctxt->instate == XML_PARSER_EOF) {
           xmlFree(name);
           return(NULL);
       }
   
     /*      /*
      * [ WFC: Entity Declared ]       * [ WFC: Entity Declared ]
Line 7515  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x Line 7806  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x
      * is not obligated to read and process their declarations;       * is not obligated to read and process their declarations;
      * for such documents, the rule that an entity must be       * for such documents, the rule that an entity must be
      * declared is a well-formedness constraint only if       * declared is a well-formedness constraint only if
     * standalone='yes'.      * standalone='yes'.
      */       */
     if (ent == NULL) {      if (ent == NULL) {
         if ((ctxt->standalone == 1) ||          if ((ctxt->standalone == 1) ||
Line 7606  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x Line 7897  xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const x
  *   *
  * [ WFC: No Recursion ]   * [ WFC: No Recursion ]
  * A parsed entity must not contain a recursive   * A parsed entity must not contain a recursive
 * reference to itself, either directly or indirectly.  * reference to itself, either directly or indirectly.
  *   *
  * [ WFC: Entity Declared ]   * [ WFC: Entity Declared ]
  * In a document without any DTD, a document with only an internal DTD   * In a document without any DTD, a document with only an internal DTD
Line 7656  xmlParsePEReference(xmlParserCtxtPtr ctxt) Line 7947  xmlParsePEReference(xmlParserCtxtPtr ctxt)
      */       */
     if ((ctxt->sax != NULL) &&      if ((ctxt->sax != NULL) &&
         (ctxt->sax->getParameterEntity != NULL))          (ctxt->sax->getParameterEntity != NULL))
        entity = ctxt->sax->getParameterEntity(ctxt->userData,        entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
                                               name);    if (ctxt->instate == XML_PARSER_EOF)
         return;
     if (entity == NULL) {      if (entity == NULL) {
         /*          /*
          * [ WFC: Entity Declared ]           * [ WFC: Entity Declared ]
Line 7787  xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityP Line 8079  xmlLoadEntityContent(xmlParserCtxtPtr ctxt, xmlEntityP
     while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) &&      while ((ctxt->input == input) && (ctxt->input->cur < ctxt->input->end) &&
            (IS_CHAR(c))) {             (IS_CHAR(c))) {
         xmlBufferAdd(buf, ctxt->input->cur, l);          xmlBufferAdd(buf, ctxt->input->cur, l);
        if (count++ > 100) {        if (count++ > XML_PARSER_CHUNK_SIZE) {
             count = 0;              count = 0;
             GROW;              GROW;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlBufferFree(buf);
                   return(-1);
               }
         }          }
         NEXTL(l);          NEXTL(l);
         c = CUR_CHAR(l);          c = CUR_CHAR(l);
           if (c == 0) {
               count = 0;
               GROW;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlBufferFree(buf);
                   return(-1);
               }
               c = CUR_CHAR(l);
           }
     }      }
   
     if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) {      if ((ctxt->input == input) && (ctxt->input->cur >= ctxt->input->end)) {
Line 7881  xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const Line 8186  xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const
      */       */
     if ((ctxt->sax != NULL) &&      if ((ctxt->sax != NULL) &&
         (ctxt->sax->getParameterEntity != NULL))          (ctxt->sax->getParameterEntity != NULL))
        entity = ctxt->sax->getParameterEntity(ctxt->userData,        entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
                                               name);    if (ctxt->instate == XML_PARSER_EOF) {
         xmlFree(name);
         return(NULL);
     }
     if (entity == NULL) {      if (entity == NULL) {
         /*          /*
          * [ WFC: Entity Declared ]           * [ WFC: Entity Declared ]
Line 7932  xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const Line 8240  xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const
  *   *
  * parse a DOCTYPE declaration   * parse a DOCTYPE declaration
  *   *
 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?  * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
  *                      ('[' (markupdecl | PEReference | S)* ']' S?)? '>'   *                      ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
  *   *
  * [ VC: Root Element Type ]   * [ VC: Root Element Type ]
  * The Name in the document type declaration must match the element   * The Name in the document type declaration must match the element
 * type of the root element.  * type of the root element.
  */   */
   
 void  void
Line 7984  xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) { Line 8292  xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt) {
     if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&      if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
         (!ctxt->disableSAX))          (!ctxt->disableSAX))
         ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI);          ctxt->sax->internalSubset(ctxt->userData, name, ExternalID, URI);
       if (ctxt->instate == XML_PARSER_EOF)
           return;
   
     /*      /*
      * Is there any internal subset declarations ?       * Is there any internal subset declarations ?
Line 8019  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { Line 8329  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
         ctxt->instate = XML_PARSER_DTD;          ctxt->instate = XML_PARSER_DTD;
         NEXT;          NEXT;
         /*          /*
         * Parse the succession of Markup declarations and          * Parse the succession of Markup declarations and
          * PEReferences.           * PEReferences.
          * Subsequence (markupdecl | PEReference | S)*           * Subsequence (markupdecl | PEReference | S)*
          */           */
        while (RAW != ']') {        while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
             const xmlChar *check = CUR_PTR;              const xmlChar *check = CUR_PTR;
             unsigned int cons = ctxt->input->consumed;              unsigned int cons = ctxt->input->consumed;
   
Line 8043  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { Line 8353  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
                 break;                  break;
             }              }
         }          }
        if (RAW == ']') {         if (RAW == ']') {
             NEXT;              NEXT;
             SKIP_BLANKS;              SKIP_BLANKS;
         }          }
Line 8074  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { Line 8384  xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
  *   *
  * [ WFC: No < in Attribute Values ]   * [ WFC: No < in Attribute Values ]
  * The replacement text of any entity referred to directly or indirectly in   * The replacement text of any entity referred to directly or indirectly in
 * an attribute value (other than "&lt;") must not contain a <.  * an attribute value (other than "&lt;") must not contain a <.
 *  *
  * [ VC: Attribute Value Type ]   * [ VC: Attribute Value Type ]
  * The attribute must have been declared; the value must be of the type   * The attribute must have been declared; the value must be of the type
  * declared for it.   * declared for it.
Line 8156  xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **val Line 8466  xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **val
 /**  /**
  * xmlParseStartTag:   * xmlParseStartTag:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse a start of tag either for rule element or   * parse a start of tag either for rule element or
  * EmptyElement. In both case we don't parse the tag closing chars.   * EmptyElement. In both case we don't parse the tag closing chars.
  *   *
Line 8164  xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **val Line 8474  xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **val
  *   *
  * [ WFC: Unique Att Spec ]   * [ WFC: Unique Att Spec ]
  * No attribute name may appear more than once in the same start-tag or   * No attribute name may appear more than once in the same start-tag or
 * empty-element tag.  * empty-element tag.
  *   *
  * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'   * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
  *   *
  * [ WFC: Unique Att Spec ]   * [ WFC: Unique Att Spec ]
  * No attribute name may appear more than once in the same start-tag or   * No attribute name may appear more than once in the same start-tag or
 * empty-element tag.  * empty-element tag.
  *   *
  * With namespace:   * With namespace:
  *   *
Line 8209  xmlParseStartTag(xmlParserCtxtPtr ctxt) { Line 8519  xmlParseStartTag(xmlParserCtxtPtr ctxt) {
     SKIP_BLANKS;      SKIP_BLANKS;
     GROW;      GROW;
   
    while ((RAW != '>') &&     while (((RAW != '>') &&
            ((RAW != '/') || (NXT(1) != '>')) &&             ((RAW != '/') || (NXT(1) != '>')) &&
           (IS_BYTE_CHAR(RAW))) {           (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
         const xmlChar *q = CUR_PTR;          const xmlChar *q = CUR_PTR;
         unsigned int cons = ctxt->input->consumed;          unsigned int cons = ctxt->input->consumed;
   
Line 8220  xmlParseStartTag(xmlParserCtxtPtr ctxt) { Line 8530  xmlParseStartTag(xmlParserCtxtPtr ctxt) {
             /*              /*
              * [ WFC: Unique Att Spec ]               * [ WFC: Unique Att Spec ]
              * No attribute name may appear more than once in the same               * No attribute name may appear more than once in the same
             * start-tag or empty-element tag.              * start-tag or empty-element tag.
              */               */
             for (i = 0; i < nbatts;i += 2) {              for (i = 0; i < nbatts;i += 2) {
                 if (xmlStrEqual(atts[i], attname)) {                  if (xmlStrEqual(atts[i], attname)) {
Line 8269  xmlParseStartTag(xmlParserCtxtPtr ctxt) { Line 8579  xmlParseStartTag(xmlParserCtxtPtr ctxt) {
                 xmlFree(attvalue);                  xmlFree(attvalue);
         }          }
   
failed:     failed:
   
         GROW          GROW
         if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))          if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
Line 8351  xmlParseEndTag1(xmlParserCtxtPtr ctxt, int line) { Line 8661  xmlParseEndTag1(xmlParserCtxtPtr ctxt, int line) {
     /*      /*
      * [ WFC: Element Type Match ]       * [ WFC: Element Type Match ]
      * The Name in an element's end-tag must match the element type in the       * The Name in an element's end-tag must match the element type in the
     * start-tag.      * start-tag.
      *       *
      */       */
     if (name != (xmlChar*)1) {      if (name != (xmlChar*)1) {
Line 8447  xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **p Line 8757  xmlParseQName(xmlParserCtxtPtr ctxt, const xmlChar **p
         if (CUR == ':') {          if (CUR == ':') {
             l = xmlParseName(ctxt);              l = xmlParseName(ctxt);
             if (l != NULL) {              if (l != NULL) {
                xmlNsErr(ctxt, XML_NS_ERR_QNAME,                 xmlNsErr(ctxt, XML_NS_ERR_QNAME,
                          "Failed to parse QName '%s'\n", l, NULL, NULL);                           "Failed to parse QName '%s'\n", l, NULL, NULL);
                 *prefix = NULL;                  *prefix = NULL;
                 return(l);                  return(l);
Line 8530  xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar Line 8840  xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar
   
     cmp = prefix;      cmp = prefix;
     while (*in != 0 && *in == *cmp) {      while (*in != 0 && *in == *cmp) {
        ++in;        ++in;
         ++cmp;          ++cmp;
     }      }
     if ((*cmp == 0) && (*in == ':')) {      if ((*cmp == 0) && (*in == ':')) {
Line 8568  xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar Line 8878  xmlParseQNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar
  *   *
  * 3.3.3 Attribute-Value Normalization:   * 3.3.3 Attribute-Value Normalization:
  * Before the value of an attribute is passed to the application or   * Before the value of an attribute is passed to the application or
 * checked for validity, the XML processor must normalize it as follows:  * checked for validity, the XML processor must normalize it as follows:
  * - a character reference is processed by appending the referenced   * - a character reference is processed by appending the referenced
  *   character to the attribute value   *   character to the attribute value
  * - an entity reference is processed by recursively processing the   * - an entity reference is processed by recursively processing the
 *   replacement text of the entity  *   replacement text of the entity
  * - a whitespace character (#x20, #xD, #xA, #x9) is processed by   * - a whitespace character (#x20, #xD, #xA, #x9) is processed by
  *   appending #x20 to the normalized value, except that only a single   *   appending #x20 to the normalized value, except that only a single
  *   #x20 is appended for a "#xD#xA" sequence that is part of an external   *   #x20 is appended for a "#xD#xA" sequence that is part of an external
 *   parsed entity or the literal entity value of an internal parsed entity  *   parsed entity or the literal entity value of an internal parsed entity
 * - other characters are processed by appending them to the normalized value  * - other characters are processed by appending them to the normalized value
  * If the declared value is not CDATA, then the XML processor must further   * If the declared value is not CDATA, then the XML processor must further
  * process the normalized attribute value by discarding any leading and   * process the normalized attribute value by discarding any leading and
  * trailing space (#x20) characters, and by replacing sequences of space   * trailing space (#x20) characters, and by replacing sequences of space
 * (#x20) characters by a single space (#x20) character.   * (#x20) characters by a single space (#x20) character.
  * All attributes for which no declaration has been read should be treated   * All attributes for which no declaration has been read should be treated
  * by a non-validating parser as if declared CDATA.   * by a non-validating parser as if declared CDATA.
  *   *
Line 8627  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 8937  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
         /*          /*
          * Skip any leading spaces           * Skip any leading spaces
          */           */
        while ((in < end) && (*in != limit) &&         while ((in < end) && (*in != limit) &&
                ((*in == 0x20) || (*in == 0x9) ||                 ((*in == 0x20) || (*in == 0x9) ||
                 (*in == 0xA) || (*in == 0xD))) {                  (*in == 0xA) || (*in == 0xD))) {
             in++;              in++;
Line 8635  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 8945  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
             if (in >= end) {              if (in >= end) {
                 const xmlChar *oldbase = ctxt->input->base;                  const xmlChar *oldbase = ctxt->input->base;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
                 if (oldbase != ctxt->input->base) {                  if (oldbase != ctxt->input->base) {
                     long delta = ctxt->input->base - oldbase;                      long delta = ctxt->input->base - oldbase;
                     start = start + delta;                      start = start + delta;
                     in = in + delta;                      in = in + delta;
                 }                  }
                 end = ctxt->input->end;                  end = ctxt->input->end;
                   if (((in - start) > XML_MAX_TEXT_LENGTH) &&
                       ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                       xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                                      "AttValue length too long\n");
                       return(NULL);
                   }
             }              }
         }          }
         while ((in < end) && (*in != limit) && (*in >= 0x20) &&          while ((in < end) && (*in != limit) && (*in >= 0x20) &&
Line 8649  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 8967  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
             if (in >= end) {              if (in >= end) {
                 const xmlChar *oldbase = ctxt->input->base;                  const xmlChar *oldbase = ctxt->input->base;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
                 if (oldbase != ctxt->input->base) {                  if (oldbase != ctxt->input->base) {
                     long delta = ctxt->input->base - oldbase;                      long delta = ctxt->input->base - oldbase;
                     start = start + delta;                      start = start + delta;
                     in = in + delta;                      in = in + delta;
                 }                  }
                 end = ctxt->input->end;                  end = ctxt->input->end;
                   if (((in - start) > XML_MAX_TEXT_LENGTH) &&
                       ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                       xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                                      "AttValue length too long\n");
                       return(NULL);
                   }
             }              }
         }          }
         last = in;          last = in;
Line 8662  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 8988  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
          * skip the trailing blanks           * skip the trailing blanks
          */           */
         while ((last[-1] == 0x20) && (last > start)) last--;          while ((last[-1] == 0x20) && (last > start)) last--;
        while ((in < end) && (*in != limit) &&         while ((in < end) && (*in != limit) &&
                ((*in == 0x20) || (*in == 0x9) ||                 ((*in == 0x20) || (*in == 0x9) ||
                 (*in == 0xA) || (*in == 0xD))) {                  (*in == 0xA) || (*in == 0xD))) {
             in++;              in++;
             if (in >= end) {              if (in >= end) {
                 const xmlChar *oldbase = ctxt->input->base;                  const xmlChar *oldbase = ctxt->input->base;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
                 if (oldbase != ctxt->input->base) {                  if (oldbase != ctxt->input->base) {
                     long delta = ctxt->input->base - oldbase;                      long delta = ctxt->input->base - oldbase;
                     start = start + delta;                      start = start + delta;
Line 8676  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 9004  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
                     last = last + delta;                      last = last + delta;
                 }                  }
                 end = ctxt->input->end;                  end = ctxt->input->end;
                   if (((in - start) > XML_MAX_TEXT_LENGTH) &&
                       ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                       xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                                      "AttValue length too long\n");
                       return(NULL);
                   }
             }              }
         }          }
           if (((in - start) > XML_MAX_TEXT_LENGTH) &&
               ((ctxt->options & XML_PARSE_HUGE) == 0)) {
               xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                              "AttValue length too long\n");
               return(NULL);
           }
         if (*in != limit) goto need_complex;          if (*in != limit) goto need_complex;
     } else {      } else {
         while ((in < end) && (*in != limit) && (*in >= 0x20) &&          while ((in < end) && (*in != limit) && (*in >= 0x20) &&
Line 8686  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l Line 9026  xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *l
             if (in >= end) {              if (in >= end) {
                 const xmlChar *oldbase = ctxt->input->base;                  const xmlChar *oldbase = ctxt->input->base;
                 GROW;                  GROW;
                   if (ctxt->instate == XML_PARSER_EOF)
                       return(NULL);
                 if (oldbase != ctxt->input->base) {                  if (oldbase != ctxt->input->base) {
                     long delta = ctxt->input->base - oldbase;                      long delta = ctxt->input->base - oldbase;
                     start = start + delta;                      start = start + delta;
                     in = in + delta;                      in = in + delta;
                 }                  }
                 end = ctxt->input->end;                  end = ctxt->input->end;
                   if (((in - start) > XML_MAX_TEXT_LENGTH) &&
                       ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                       xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                                      "AttValue length too long\n");
                       return(NULL);
                   }
             }              }
         }          }
         last = in;          last = in;
           if (((in - start) > XML_MAX_TEXT_LENGTH) &&
               ((ctxt->options & XML_PARSE_HUGE) == 0)) {
               xmlFatalErrMsg(ctxt, XML_ERR_ATTRIBUTE_NOT_FINISHED,
                              "AttValue length too long\n");
               return(NULL);
           }
         if (*in != limit) goto need_complex;          if (*in != limit) goto need_complex;
     }      }
     in++;      in++;
Line 8833  xmlParseAttribute2(xmlParserCtxtPtr ctxt, Line 9187  xmlParseAttribute2(xmlParserCtxtPtr ctxt,
 /**  /**
  * xmlParseStartTag2:   * xmlParseStartTag2:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse a start of tag either for rule element or   * parse a start of tag either for rule element or
  * EmptyElement. In both case we don't parse the tag closing chars.   * EmptyElement. In both case we don't parse the tag closing chars.
  * This routine is called when running SAX2 parsing   * This routine is called when running SAX2 parsing
Line 8842  xmlParseAttribute2(xmlParserCtxtPtr ctxt, Line 9196  xmlParseAttribute2(xmlParserCtxtPtr ctxt,
  *   *
  * [ WFC: Unique Att Spec ]   * [ WFC: Unique Att Spec ]
  * No attribute name may appear more than once in the same start-tag or   * No attribute name may appear more than once in the same start-tag or
 * empty-element tag.  * empty-element tag.
  *   *
  * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'   * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
  *   *
  * [ WFC: Unique Att Spec ]   * [ WFC: Unique Att Spec ]
  * No attribute name may appear more than once in the same start-tag or   * No attribute name may appear more than once in the same start-tag or
 * empty-element tag.  * empty-element tag.
  *   *
  * With namespace:   * With namespace:
  *   *
Line 8917  reparse: Line 9271  reparse:
     GROW;      GROW;
     if (ctxt->input->base != base) goto base_changed;      if (ctxt->input->base != base) goto base_changed;
   
    while ((RAW != '>') &&     while (((RAW != '>') &&
            ((RAW != '/') || (NXT(1) != '>')) &&             ((RAW != '/') || (NXT(1) != '>')) &&
           (IS_BYTE_CHAR(RAW))) {           (IS_BYTE_CHAR(RAW))) && (ctxt->instate != XML_PARSER_EOF)) {
         const xmlChar *q = CUR_PTR;          const xmlChar *q = CUR_PTR;
         unsigned int cons = ctxt->input->consumed;          unsigned int cons = ctxt->input->consumed;
         int len = -1, alloc = 0;          int len = -1, alloc = 0;
Line 9090  skip_ns: Line 9444  skip_ns:
 failed:  failed:
   
         GROW          GROW
           if (ctxt->instate == XML_PARSER_EOF)
               break;
         if (ctxt->input->base != base) goto base_changed;          if (ctxt->input->base != base) goto base_changed;
         if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))          if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
             break;              break;
Line 9181  failed: Line 9537  failed:
                     atts[nbatts++] = defaults->values[5 * i + 3];                      atts[nbatts++] = defaults->values[5 * i + 3];
                     if ((ctxt->standalone == 1) &&                      if ((ctxt->standalone == 1) &&
                         (defaults->values[5 * i + 4] != NULL)) {                          (defaults->values[5 * i + 4] != NULL)) {
                        xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,                         xmlValidityError(ctxt, XML_DTD_STANDALONE_DEFAULTED,
           "standalone: attribute %s on %s defaulted from external subset\n",            "standalone: attribute %s on %s defaulted from external subset\n",
                                          attname, localname);                                           attname, localname);
                     }                      }
Line 9211  failed: Line 9567  failed:
         /*          /*
          * [ WFC: Unique Att Spec ]           * [ WFC: Unique Att Spec ]
          * No attribute name may appear more than once in the same           * No attribute name may appear more than once in the same
         * start-tag or empty-element tag.          * start-tag or empty-element tag.
          * As extended by the Namespace in XML REC.           * As extended by the Namespace in XML REC.
          */           */
         for (j = 0; j < i;j += 5) {          for (j = 0; j < i;j += 5) {
Line 9327  xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar * Line 9683  xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *
      * We should definitely be at the ending "S? '>'" part       * We should definitely be at the ending "S? '>'" part
      */       */
     GROW;      GROW;
       if (ctxt->instate == XML_PARSER_EOF)
           return;
     SKIP_BLANKS;      SKIP_BLANKS;
     if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {      if ((!IS_BYTE_CHAR(RAW)) || (RAW != '>')) {
         xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);          xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
Line 9336  xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar * Line 9694  xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *
     /*      /*
      * [ WFC: Element Type Match ]       * [ WFC: Element Type Match ]
      * The Name in an element's end-tag must match the element type in the       * The Name in an element's end-tag must match the element type in the
     * start-tag.      * start-tag.
      *       *
      */       */
     if (name != (xmlChar*)1) {      if (name != (xmlChar*)1) {
Line 9365  done: Line 9723  done:
 /**  /**
  * xmlParseCDSect:   * xmlParseCDSect:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * Parse escaped pure raw content.   * Parse escaped pure raw content.
  *   *
  * [18] CDSect ::= CDStart CData CDEnd   * [18] CDSect ::= CDStart CData CDEnd
Line 9418  xmlParseCDSect(xmlParserCtxtPtr ctxt) { Line 9776  xmlParseCDSect(xmlParserCtxtPtr ctxt) {
         if (len + 5 >= size) {          if (len + 5 >= size) {
             xmlChar *tmp;              xmlChar *tmp;
   
            size *= 2;            if ((size > XML_MAX_TEXT_LENGTH) &&
            tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));                ((ctxt->options & XML_PARSE_HUGE) == 0)) {
                 xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED,
                              "CData section too big found", NULL);
                 xmlFree (buf);
                 return;
             }
             tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar));
             if (tmp == NULL) {              if (tmp == NULL) {
                 xmlFree(buf);                  xmlFree(buf);
                 xmlErrMemory(ctxt, NULL);                  xmlErrMemory(ctxt, NULL);
                 return;                  return;
             }              }
             buf = tmp;              buf = tmp;
               size *= 2;
         }          }
         COPY_BUF(rl,buf,len,r);          COPY_BUF(rl,buf,len,r);
         r = s;          r = s;
Line 9435  xmlParseCDSect(xmlParserCtxtPtr ctxt) { Line 9800  xmlParseCDSect(xmlParserCtxtPtr ctxt) {
         count++;          count++;
         if (count > 50) {          if (count > 50) {
             GROW;              GROW;
               if (ctxt->instate == XML_PARSER_EOF) {
                   xmlFree(buf);
                   return;
               }
             count = 0;              count = 0;
         }          }
         NEXTL(l);          NEXTL(l);
Line 9514  xmlParseContent(xmlParserCtxtPtr ctxt) { Line 9883  xmlParseContent(xmlParserCtxtPtr ctxt) {
   
         /*          /*
          * Fifth case : a reference. If if has not been resolved,           * Fifth case : a reference. If if has not been resolved,
         *    parsing returns it's Name, create the node          *    parsing returns it's Name, create the node
          */           */
   
         else if (*cur == '&') {          else if (*cur == '&') {
Line 9555  xmlParseContent(xmlParserCtxtPtr ctxt) { Line 9924  xmlParseContent(xmlParserCtxtPtr ctxt) {
  *   *
  * [ WFC: Element Type Match ]   * [ WFC: Element Type Match ]
  * The Name in an element's end-tag must match the element type in the   * The Name in an element's end-tag must match the element type in the
 * start-tag.  * start-tag.
  *   *
  */   */
   
Line 9614  xmlParseElement(xmlParserCtxtPtr ctxt) { Line 9983  xmlParseElement(xmlParserCtxtPtr ctxt) {
     /*      /*
      * [ VC: Root Element Type ]       * [ VC: Root Element Type ]
      * The Name in the document type declaration must match the element       * The Name in the document type declaration must match the element
     * type of the root element.      * type of the root element.
      */       */
     if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&      if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
         ctxt->node && (ctxt->node == ctxt->myDoc->children))          ctxt->node && (ctxt->node == ctxt->myDoc->children))
Line 9683  xmlParseElement(xmlParserCtxtPtr ctxt) { Line 10052  xmlParseElement(xmlParserCtxtPtr ctxt) {
      * Parse the content of the element:       * Parse the content of the element:
      */       */
     xmlParseContent(ctxt);      xmlParseContent(ctxt);
       if (ctxt->instate == XML_PARSER_EOF)
           return;
     if (!IS_BYTE_CHAR(RAW)) {      if (!IS_BYTE_CHAR(RAW)) {
         xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,          xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
          "Premature end of data in tag %s line %d\n",           "Premature end of data in tag %s line %d\n",
Line 9895  xmlParseEncName(xmlParserCtxtPtr ctxt) { Line 10266  xmlParseEncName(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseEncodingDecl:   * xmlParseEncodingDecl:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse the XML encoding declaration   * parse the XML encoding declaration
  *   *
  * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' |  "'" EncName "'")   * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' |  "'" EncName "'")
Line 9952  xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { Line 10323  xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
              (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) {               (!xmlStrcasecmp(encoding, BAD_CAST "UTF16")))) {
             /*              /*
              * If no encoding was passed to the parser, that we are               * If no encoding was passed to the parser, that we are
             * using UTF-16 and no decoder is present i.e. the              * using UTF-16 and no decoder is present i.e. the
              * document is apparently UTF-8 compatible, then raise an               * document is apparently UTF-8 compatible, then raise an
              * encoding mismatch fatal error               * encoding mismatch fatal error
              */               */
Line 10003  xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) { Line 10374  xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
  * parse the XML standalone declaration   * parse the XML standalone declaration
  *   *
  * [32] SDDecl ::= S 'standalone' Eq   * [32] SDDecl ::= S 'standalone' Eq
 *                 (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))  *                 (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"'))
  *   *
  * [ VC: Standalone Document Declaration ]   * [ VC: Standalone Document Declaration ]
  * TODO The standalone document declaration must have the value "no"   * TODO The standalone document declaration must have the value "no"
Line 10083  xmlParseSDDecl(xmlParserCtxtPtr ctxt) { Line 10454  xmlParseSDDecl(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseXMLDecl:   * xmlParseXMLDecl:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse an XML declaration header   * parse an XML declaration header
  *   *
  * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'   * [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
Line 10197  xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { Line 10568  xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseMisc:   * xmlParseMisc:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse an XML Misc* optional field.   * parse an XML Misc* optional field.
  *   *
  * [27] Misc ::= Comment | PI |  S   * [27] Misc ::= Comment | PI |  S
Line 10205  xmlParseXMLDecl(xmlParserCtxtPtr ctxt) { Line 10576  xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
   
 void  void
 xmlParseMisc(xmlParserCtxtPtr ctxt) {  xmlParseMisc(xmlParserCtxtPtr ctxt) {
    while (((RAW == '<') && (NXT(1) == '?')) ||    while ((ctxt->instate != XML_PARSER_EOF) &&
           (CMP4(CUR_PTR, '<', '!', '-', '-')) ||           (((RAW == '<') && (NXT(1) == '?')) ||
           IS_BLANK_CH(CUR)) {            (CMP4(CUR_PTR, '<', '!', '-', '-')) ||
             IS_BLANK_CH(CUR))) {
         if ((RAW == '<') && (NXT(1) == '?')) {          if ((RAW == '<') && (NXT(1) == '?')) {
             xmlParsePI(ctxt);              xmlParsePI(ctxt);
         } else if (IS_BLANK_CH(CUR)) {          } else if (IS_BLANK_CH(CUR)) {
Line 10220  xmlParseMisc(xmlParserCtxtPtr ctxt) { Line 10592  xmlParseMisc(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseDocument:   * xmlParseDocument:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse an XML document (and build a tree if using the standard SAX   * parse an XML document (and build a tree if using the standard SAX
  * interface).   * interface).
  *   *
Line 10254  xmlParseDocument(xmlParserCtxtPtr ctxt) { Line 10626  xmlParseDocument(xmlParserCtxtPtr ctxt) {
      */       */
     if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))      if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
         ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);          ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
   
     if ((ctxt->encoding == NULL) &&      if ((ctxt->encoding == NULL) &&
         ((ctxt->input->end - ctxt->input->cur) >= 4)) {          ((ctxt->input->end - ctxt->input->cur) >= 4)) {
        /*         /*
          * Get the 4 first bytes and decode the charset           * Get the 4 first bytes and decode the charset
          * if enc != XML_CHAR_ENCODING_NONE           * if enc != XML_CHAR_ENCODING_NONE
          * plug some encoding conversion routines.           * plug some encoding conversion routines.
Line 10305  xmlParseDocument(xmlParserCtxtPtr ctxt) { Line 10679  xmlParseDocument(xmlParserCtxtPtr ctxt) {
     }      }
     if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))      if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
         ctxt->sax->startDocument(ctxt->userData);          ctxt->sax->startDocument(ctxt->userData);
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
   
     /*      /*
      * The Misc part of the Prolog       * The Misc part of the Prolog
Line 10324  xmlParseDocument(xmlParserCtxtPtr ctxt) { Line 10700  xmlParseDocument(xmlParserCtxtPtr ctxt) {
         if (RAW == '[') {          if (RAW == '[') {
             ctxt->instate = XML_PARSER_DTD;              ctxt->instate = XML_PARSER_DTD;
             xmlParseInternalSubset(ctxt);              xmlParseInternalSubset(ctxt);
               if (ctxt->instate == XML_PARSER_EOF)
                   return(-1);
         }          }
   
         /*          /*
Line 10334  xmlParseDocument(xmlParserCtxtPtr ctxt) { Line 10712  xmlParseDocument(xmlParserCtxtPtr ctxt) {
             (!ctxt->disableSAX))              (!ctxt->disableSAX))
             ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName,              ctxt->sax->externalSubset(ctxt->userData, ctxt->intSubName,
                                       ctxt->extSubSystem, ctxt->extSubURI);                                        ctxt->extSubSystem, ctxt->extSubURI);
           if (ctxt->instate == XML_PARSER_EOF)
               return(-1);
         ctxt->inSubset = 0;          ctxt->inSubset = 0;
   
         xmlCleanSpecialAttr(ctxt);          xmlCleanSpecialAttr(ctxt);
Line 10400  xmlParseDocument(xmlParserCtxtPtr ctxt) { Line 10780  xmlParseDocument(xmlParserCtxtPtr ctxt) {
 /**  /**
  * xmlParseExtParsedEnt:   * xmlParseExtParsedEnt:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
 *  *
  * parse a general parsed entity   * parse a general parsed entity
  * An external general parsed entity is well-formed if it matches the   * An external general parsed entity is well-formed if it matches the
  * production labeled extParsedEnt.   * production labeled extParsedEnt.
Line 10431  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { Line 10811  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
     if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))      if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
         ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);          ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
   
    /*     /*
      * Get the 4 first bytes and decode the charset       * Get the 4 first bytes and decode the charset
      * if enc != XML_CHAR_ENCODING_NONE       * if enc != XML_CHAR_ENCODING_NONE
      * plug some encoding conversion routines.       * plug some encoding conversion routines.
Line 10474  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { Line 10854  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
     }      }
     if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))      if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
         ctxt->sax->startDocument(ctxt->userData);          ctxt->sax->startDocument(ctxt->userData);
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
   
     /*      /*
      * Doing validity checking on chunk doesn't make sense       * Doing validity checking on chunk doesn't make sense
Line 10484  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { Line 10866  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
     ctxt->depth = 0;      ctxt->depth = 0;
   
     xmlParseContent(ctxt);      xmlParseContent(ctxt);
       if (ctxt->instate == XML_PARSER_EOF)
         return(-1);
 
     if ((RAW == '<') && (NXT(1) == '/')) {      if ((RAW == '<') && (NXT(1) == '/')) {
         xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL);          xmlFatalErr(ctxt, XML_ERR_NOT_WELL_BALANCED, NULL);
     } else if (RAW != 0) {      } else if (RAW != 0) {
Line 10504  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) { Line 10888  xmlParseExtParsedEnt(xmlParserCtxtPtr ctxt) {
 #ifdef LIBXML_PUSH_ENABLED  #ifdef LIBXML_PUSH_ENABLED
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Progressive parsing interfaces                          * *                Progressive parsing interfaces                          *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 10541  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar  Line 10925  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar 
         buf = in->base;          buf = in->base;
         len = in->length;          len = in->length;
     } else {      } else {
        buf = in->buf->buffer->content;        buf = xmlBufContent(in->buf->buffer);
        len = in->buf->buffer->use;        len = xmlBufUse(in->buf->buffer);
     }      }
     /* take into account the sequence length */      /* take into account the sequence length */
     if (third) len -= 2;      if (third) len -= 2;
Line 10565  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar  Line 10949  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar 
                 xmlGenericError(xmlGenericErrorContext,                  xmlGenericError(xmlGenericErrorContext,
                         "PP: lookup '%c%c' found at %d\n",                          "PP: lookup '%c%c' found at %d\n",
                         first, next, base);                          first, next, base);
            else             else
                 xmlGenericError(xmlGenericErrorContext,                  xmlGenericError(xmlGenericErrorContext,
                         "PP: lookup '%c%c%c' found at %d\n",                          "PP: lookup '%c%c%c' found at %d\n",
                         first, next, third, base);                          first, next, third, base);
Line 10581  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar  Line 10965  xmlParseLookupSequence(xmlParserCtxtPtr ctxt, xmlChar 
     else if (third == 0)      else if (third == 0)
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
                 "PP: lookup '%c%c' failed\n", first, next);                  "PP: lookup '%c%c' failed\n", first, next);
    else            else
         xmlGenericError(xmlGenericErrorContext,          xmlGenericError(xmlGenericErrorContext,
                 "PP: lookup '%c%c%c' failed\n", first, next, third);                  "PP: lookup '%c%c%c' failed\n", first, next, third);
 #endif  #endif
Line 10663  xmlCheckCdataPush(const xmlChar *utf, int len) { Line 11047  xmlCheckCdataPush(const xmlChar *utf, int len) {
   
     if ((utf == NULL) || (len <= 0))      if ((utf == NULL) || (len <= 0))
         return(0);          return(0);
    
     for (ix = 0; ix < len;) {      /* string is 0-terminated */      for (ix = 0; ix < len;) {      /* string is 0-terminated */
         c = utf[ix];          c = utf[ix];
         if ((c & 0x80) == 0x00) {       /* 1-byte code, starts with 10 */          if ((c & 0x80) == 0x00) {       /* 1-byte code, starts with 10 */
Line 10791  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11175  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
     }      }
     xmlParseGetLasts(ctxt, &lastlt, &lastgt);      xmlParseGetLasts(ctxt, &lastlt, &lastgt);
   
    while (1) {    while (ctxt->instate != XML_PARSER_EOF) {
         if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))          if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
             return(0);              return(0);
   
        
         /*          /*
          * Pop-up of finished entities.           * Pop-up of finished entities.
          */           */
Line 10810  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11194  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
             /*              /*
              * If we are operating on converted input, try to flush               * If we are operating on converted input, try to flush
              * remainng chars to avoid them stalling in the non-converted               * remainng chars to avoid them stalling in the non-converted
             * buffer.             * buffer. But do not do this in document start where
              * encoding="..." may not have been read and we work on a
              * guessed encoding.
              */               */
            if ((ctxt->input->buf->raw != NULL) &&            if ((ctxt->instate != XML_PARSER_START) &&
                (ctxt->input->buf->raw->use > 0)) {                (ctxt->input->buf->raw != NULL) &&
                int base = ctxt->input->base -                (xmlBufIsEmpty(ctxt->input->buf->raw) == 0)) {
                           ctxt->input->buf->buffer->content;                size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
                int current = ctxt->input->cur - ctxt->input->base;                                                 ctxt->input);
                 size_t current = ctxt->input->cur - ctxt->input->base;
   
                 xmlParserInputBufferPush(ctxt->input->buf, 0, "");                  xmlParserInputBufferPush(ctxt->input->buf, 0, "");
                ctxt->input->base = ctxt->input->buf->buffer->content + base;                xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
                ctxt->input->cur = ctxt->input->base + current;                                      base, current);
                ctxt->input->end = 
                    &ctxt->input->buf->buffer->content[ 
                                       ctxt->input->buf->buffer->use]; 
             }              }
            avail = ctxt->input->buf->buffer->use -            avail = xmlBufUse(ctxt->input->buf->buffer) -
                     (ctxt->input->cur - ctxt->input->base);                      (ctxt->input->cur - ctxt->input->base);
         }          }
         if (avail < 1)          if (avail < 1)
Line 10847  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11231  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     if (avail < 4)                      if (avail < 4)
                         goto done;                          goto done;
   
                    /*                     /*
                      * Get the 4 first bytes and decode the charset                       * Get the 4 first bytes and decode the charset
                      * if enc != XML_CHAR_ENCODING_NONE                       * if enc != XML_CHAR_ENCODING_NONE
                      * plug some encoding conversion routines,                       * plug some encoding conversion routines,
Line 11002  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11386  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 /*                  /*
                  * [ VC: Root Element Type ]                   * [ VC: Root Element Type ]
                  * The Name in the document type declaration must match                   * The Name in the document type declaration must match
                 * the element type of the root element.                  * the element type of the root element.
                  */                   */
                 if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&                  if (ctxt->validate && ctxt->wellFormed && ctxt->myDoc &&
                     ctxt->node && (ctxt->node == ctxt->myDoc->children))                      ctxt->node && (ctxt->node == ctxt->myDoc->children))
Line 11031  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11415  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                             ctxt->sax->endElement(ctxt->userData, name);                              ctxt->sax->endElement(ctxt->userData, name);
 #endif /* LIBXML_SAX1_ENABLED */  #endif /* LIBXML_SAX1_ENABLED */
                     }                      }
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     spacePop(ctxt);                      spacePop(ctxt);
                     if (ctxt->nameNr == 0) {                      if (ctxt->nameNr == 0) {
                         ctxt->instate = XML_PARSER_EPILOG;                          ctxt->instate = XML_PARSER_EPILOG;
                     } else {                      } else {
                         ctxt->instate = XML_PARSER_CONTENT;                          ctxt->instate = XML_PARSER_CONTENT;
                     }                      }
                       ctxt->progressive = 1;
                     break;                      break;
                 }                  }
                 if (RAW == '>') {                  if (RAW == '>') {
Line 11056  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11443  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
 #endif /* LIBXML_SAX1_ENABLED */  #endif /* LIBXML_SAX1_ENABLED */
   
                 ctxt->instate = XML_PARSER_CONTENT;                  ctxt->instate = XML_PARSER_CONTENT;
                   ctxt->progressive = 1;
                 break;                  break;
             }              }
             case XML_PARSER_CONTENT: {              case XML_PARSER_CONTENT: {
Line 11073  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11461  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     break;                      break;
                 } else if ((cur == '<') && (next == '?')) {                  } else if ((cur == '<') && (next == '?')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0))                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
                         ctxt->progressive = XML_PARSER_PI;
                         goto done;                          goto done;
                       }
                     xmlParsePI(ctxt);                      xmlParsePI(ctxt);
                       ctxt->instate = XML_PARSER_CONTENT;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (next != '!')) {                  } else if ((cur == '<') && (next != '!')) {
                     ctxt->instate = XML_PARSER_START_TAG;                      ctxt->instate = XML_PARSER_START_TAG;
                     break;                      break;
Line 11089  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11481  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     ctxt->input->cur += 4;                      ctxt->input->cur += 4;
                     term = xmlParseLookupSequence(ctxt, '-', '-', '>');                      term = xmlParseLookupSequence(ctxt, '-', '-', '>');
                     ctxt->input->cur -= 4;                      ctxt->input->cur -= 4;
                    if ((!terminate) && (term < 0))                    if ((!terminate) && (term < 0)) {
                         ctxt->progressive = XML_PARSER_COMMENT;
                         goto done;                          goto done;
                       }
                     xmlParseComment(ctxt);                      xmlParseComment(ctxt);
                     ctxt->instate = XML_PARSER_CONTENT;                      ctxt->instate = XML_PARSER_CONTENT;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (ctxt->input->cur[1] == '!') &&                  } else if ((cur == '<') && (ctxt->input->cur[1] == '!') &&
                     (ctxt->input->cur[2] == '[') &&                      (ctxt->input->cur[2] == '[') &&
                     (ctxt->input->cur[3] == 'C') &&                      (ctxt->input->cur[3] == 'C') &&
Line 11187  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11582  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 break;                  break;
             case XML_PARSER_CDATA_SECTION: {              case XML_PARSER_CDATA_SECTION: {
                 /*                  /*
                 * The Push mode need to have the SAX callback for                  * The Push mode need to have the SAX callback for
                  * cdataBlock merge back contiguous callbacks.                   * cdataBlock merge back contiguous callbacks.
                  */                   */
                 int base;                  int base;
Line 11197  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11592  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) {                      if (avail >= XML_PARSER_BIG_BUFFER_SIZE + 2) {
                         int tmp;                          int tmp;
   
                        tmp = xmlCheckCdataPush(ctxt->input->cur,                         tmp = xmlCheckCdataPush(ctxt->input->cur,
                                                 XML_PARSER_BIG_BUFFER_SIZE);                                                  XML_PARSER_BIG_BUFFER_SIZE);
                         if (tmp < 0) {                          if (tmp < 0) {
                             tmp = -tmp;                              tmp = -tmp;
Line 11212  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11607  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                                 ctxt->sax->characters(ctxt->userData,                                  ctxt->sax->characters(ctxt->userData,
                                                       ctxt->input->cur, tmp);                                                        ctxt->input->cur, tmp);
                         }                          }
                           if (ctxt->instate == XML_PARSER_EOF)
                               goto done;
                         SKIPL(tmp);                          SKIPL(tmp);
                         ctxt->checkIndex = 0;                          ctxt->checkIndex = 0;
                     }                      }
Line 11247  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11644  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                             ctxt->sax->characters(ctxt->userData,                              ctxt->sax->characters(ctxt->userData,
                                                   ctxt->input->cur, base);                                                    ctxt->input->cur, base);
                     }                      }
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     SKIPL(base + 3);                      SKIPL(base + 3);
                     ctxt->checkIndex = 0;                      ctxt->checkIndex = 0;
                     ctxt->instate = XML_PARSER_CONTENT;                      ctxt->instate = XML_PARSER_CONTENT;
Line 11263  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11662  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     avail = ctxt->input->length -                      avail = ctxt->input->length -
                             (ctxt->input->cur - ctxt->input->base);                              (ctxt->input->cur - ctxt->input->base);
                 else                  else
                    avail = ctxt->input->buf->buffer->use -                    avail = xmlBufUse(ctxt->input->buf->buffer) -
                             (ctxt->input->cur - ctxt->input->base);                              (ctxt->input->cur - ctxt->input->base);
                 if (avail < 2)                  if (avail < 2)
                     goto done;                      goto done;
Line 11271  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11670  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 next = ctxt->input->cur[1];                  next = ctxt->input->cur[1];
                 if ((cur == '<') && (next == '?')) {                  if ((cur == '<') && (next == '?')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0))                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
                         ctxt->progressive = XML_PARSER_PI;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing PI\n");                              "PP: Parsing PI\n");
 #endif  #endif
                     xmlParsePI(ctxt);                      xmlParsePI(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                       ctxt->instate = XML_PARSER_MISC;
                       ctxt->progressive = 1;
                     ctxt->checkIndex = 0;                      ctxt->checkIndex = 0;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                     (ctxt->input->cur[2] == '-') &&                      (ctxt->input->cur[2] == '-') &&
                     (ctxt->input->cur[3] == '-')) {                      (ctxt->input->cur[3] == '-')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0))                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
                         ctxt->progressive = XML_PARSER_COMMENT;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing Comment\n");                              "PP: Parsing Comment\n");
 #endif  #endif
                     xmlParseComment(ctxt);                      xmlParseComment(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     ctxt->instate = XML_PARSER_MISC;                      ctxt->instate = XML_PARSER_MISC;
                       ctxt->progressive = 1;
                     ctxt->checkIndex = 0;                      ctxt->checkIndex = 0;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                     (ctxt->input->cur[2] == 'D') &&                      (ctxt->input->cur[2] == 'D') &&
Line 11301  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11711  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     (ctxt->input->cur[7] == 'P') &&                      (ctxt->input->cur[7] == 'P') &&
                     (ctxt->input->cur[8] == 'E')) {                      (ctxt->input->cur[8] == 'E')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0))                        (xmlParseLookupSequence(ctxt, '>', 0, 0) < 0)) {
                         ctxt->progressive = XML_PARSER_DTD;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing internal subset\n");                              "PP: Parsing internal subset\n");
 #endif  #endif
                     ctxt->inSubset = 1;                      ctxt->inSubset = 1;
                       ctxt->progressive = 0;
                       ctxt->checkIndex = 0;
                     xmlParseDocTypeDecl(ctxt);                      xmlParseDocTypeDecl(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     if (RAW == '[') {                      if (RAW == '[') {
                         ctxt->instate = XML_PARSER_DTD;                          ctxt->instate = XML_PARSER_DTD;
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
Line 11338  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11754  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                     goto done;                      goto done;
                 } else {                  } else {
                     ctxt->instate = XML_PARSER_START_TAG;                      ctxt->instate = XML_PARSER_START_TAG;
                    ctxt->progressive = 1;                    ctxt->progressive = XML_PARSER_START_TAG;
                     xmlParseGetLasts(ctxt, &lastlt, &lastgt);                      xmlParseGetLasts(ctxt, &lastlt, &lastgt);
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
Line 11351  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11767  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 if (ctxt->input->buf == NULL)                  if (ctxt->input->buf == NULL)
                     avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base);                      avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base);
                 else                  else
                    avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base);                    avail = xmlBufUse(ctxt->input->buf->buffer) -
                if (avail < 2)                             (ctxt->input->cur - ctxt->input->base);
                 if (avail < 2)
                     goto done;                      goto done;
                 cur = ctxt->input->cur[0];                  cur = ctxt->input->cur[0];
                 next = ctxt->input->cur[1];                  next = ctxt->input->cur[1];
                 if ((cur == '<') && (next == '?')) {                  if ((cur == '<') && (next == '?')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0))                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
                         ctxt->progressive = XML_PARSER_PI;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing PI\n");                              "PP: Parsing PI\n");
 #endif  #endif
                     xmlParsePI(ctxt);                      xmlParsePI(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                       ctxt->instate = XML_PARSER_PROLOG;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                     (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) {                      (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0))                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
                         ctxt->progressive = XML_PARSER_COMMENT;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing Comment\n");                              "PP: Parsing Comment\n");
 #endif  #endif
                     xmlParseComment(ctxt);                      xmlParseComment(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     ctxt->instate = XML_PARSER_PROLOG;                      ctxt->instate = XML_PARSER_PROLOG;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                            (avail < 4)) {                             (avail < 4)) {
                     goto done;                      goto done;
                 } else {                  } else {
                     ctxt->instate = XML_PARSER_START_TAG;                      ctxt->instate = XML_PARSER_START_TAG;
                     if (ctxt->progressive == 0)                      if (ctxt->progressive == 0)
                        ctxt->progressive = 1;                        ctxt->progressive = XML_PARSER_START_TAG;
                     xmlParseGetLasts(ctxt, &lastlt, &lastgt);                      xmlParseGetLasts(ctxt, &lastlt, &lastgt);
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
Line 11395  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11823  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 if (ctxt->input->buf == NULL)                  if (ctxt->input->buf == NULL)
                     avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base);                      avail = ctxt->input->length - (ctxt->input->cur - ctxt->input->base);
                 else                  else
                    avail = ctxt->input->buf->buffer->use - (ctxt->input->cur - ctxt->input->base);                    avail = xmlBufUse(ctxt->input->buf->buffer) -
                             (ctxt->input->cur - ctxt->input->base);
                 if (avail < 2)                  if (avail < 2)
                     goto done;                      goto done;
                 cur = ctxt->input->cur[0];                  cur = ctxt->input->cur[0];
                 next = ctxt->input->cur[1];                  next = ctxt->input->cur[1];
                 if ((cur == '<') && (next == '?')) {                  if ((cur == '<') && (next == '?')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0))                        (xmlParseLookupSequence(ctxt, '?', '>', 0) < 0)) {
                         ctxt->progressive = XML_PARSER_PI;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing PI\n");                              "PP: Parsing PI\n");
 #endif  #endif
                     xmlParsePI(ctxt);                      xmlParsePI(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     ctxt->instate = XML_PARSER_EPILOG;                      ctxt->instate = XML_PARSER_EPILOG;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                     (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) {                      (ctxt->input->cur[2] == '-') && (ctxt->input->cur[3] == '-')) {
                     if ((!terminate) &&                      if ((!terminate) &&
                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0))                        (xmlParseLookupSequence(ctxt, '-', '-', '>') < 0)) {
                         ctxt->progressive = XML_PARSER_COMMENT;
                         goto done;                          goto done;
                       }
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                             "PP: Parsing Comment\n");                              "PP: Parsing Comment\n");
 #endif  #endif
                     xmlParseComment(ctxt);                      xmlParseComment(ctxt);
                       if (ctxt->instate == XML_PARSER_EOF)
                           goto done;
                     ctxt->instate = XML_PARSER_EPILOG;                      ctxt->instate = XML_PARSER_EPILOG;
                       ctxt->progressive = 1;
                 } else if ((cur == '<') && (next == '!') &&                  } else if ((cur == '<') && (next == '!') &&
                            (avail < 4)) {                             (avail < 4)) {
                     goto done;                      goto done;
Line 11450  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11889  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                 int base, i;                  int base, i;
                 xmlChar *buf;                  xmlChar *buf;
                 xmlChar quote = 0;                  xmlChar quote = 0;
                   size_t use;
   
                 base = ctxt->input->cur - ctxt->input->base;                  base = ctxt->input->cur - ctxt->input->base;
                 if (base < 0) return(0);                  if (base < 0) return(0);
                 if (ctxt->checkIndex > base)                  if (ctxt->checkIndex > base)
                     base = ctxt->checkIndex;                      base = ctxt->checkIndex;
                buf = ctxt->input->buf->buffer->content;                buf = xmlBufContent(ctxt->input->buf->buffer);
                for (;(unsigned int) base < ctxt->input->buf->buffer->use;                use = xmlBufUse(ctxt->input->buf->buffer);
                     base++) {                for (;(unsigned int) base < use; base++) {
                     if (quote != 0) {                      if (quote != 0) {
                         if (buf[base] == quote)                          if (buf[base] == quote)
                             quote = 0;                              quote = 0;
                        continue;                            continue;
                     }                      }
                     if ((quote == 0) && (buf[base] == '<')) {                      if ((quote == 0) && (buf[base] == '<')) {
                         int found  = 0;                          int found  = 0;
                         /* special handling of comments */                          /* special handling of comments */
                        if (((unsigned int) base + 4 <                        if (((unsigned int) base + 4 < use) &&
                             ctxt->input->buf->buffer->use) && 
                             (buf[base + 1] == '!') &&                              (buf[base + 1] == '!') &&
                             (buf[base + 2] == '-') &&                              (buf[base + 2] == '-') &&
                             (buf[base + 3] == '-')) {                              (buf[base + 3] == '-')) {
                            for (;(unsigned int) base + 3 <                            for (;(unsigned int) base + 3 < use; base++) {
                                  ctxt->input->buf->buffer->use; base++) { 
                                 if ((buf[base] == '-') &&                                  if ((buf[base] == '-') &&
                                     (buf[base + 1] == '-') &&                                      (buf[base + 1] == '-') &&
                                     (buf[base + 2] == '>')) {                                      (buf[base + 2] == '>')) {
Line 11503  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11941  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                         fprintf(stderr, "%c%c%c%c: ", buf[base],                          fprintf(stderr, "%c%c%c%c: ", buf[base],
                                 buf[base + 1], buf[base + 2], buf[base + 3]);                                  buf[base + 1], buf[base + 2], buf[base + 3]);
 #endif  #endif
                        if ((unsigned int) base +1 >=                        if ((unsigned int) base +1 >= use)
                            ctxt->input->buf->buffer->use) 
                             break;                              break;
                         if (buf[base + 1] == ']') {                          if (buf[base + 1] == ']') {
                             /* conditional crap, skip both ']' ! */                              /* conditional crap, skip both ']' ! */
                             base++;                              base++;
                             continue;                              continue;
                         }                          }
                        for (i = 1;                        for (i = 1; (unsigned int) base + i < use; i++) {
                     (unsigned int) base + i < ctxt->input->buf->buffer->use; 
                             i++) { 
                             if (buf[base + i] == '>') {                              if (buf[base + i] == '>') {
 #if 0  #if 0
                                 fprintf(stderr, "found\n");                                  fprintf(stderr, "found\n");
Line 11531  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina Line 11966  xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int termina
                         fprintf(stderr, "end of stream\n");                          fprintf(stderr, "end of stream\n");
 #endif  #endif
                         break;                          break;
                        
                     }                      }
 not_end_of_int_subset:  not_end_of_int_subset:
                     continue; /* for */                      continue; /* for */
Line 11539  not_end_of_int_subset: Line 11974  not_end_of_int_subset:
                 /*                  /*
                  * We didn't found the end of the Internal subset                   * We didn't found the end of the Internal subset
                  */                   */
                   if (quote == 0)
                       ctxt->checkIndex = base;
                   else
                       ctxt->checkIndex = 0;
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
                 if (next == 0)                  if (next == 0)
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
Line 11547  not_end_of_int_subset: Line 11986  not_end_of_int_subset:
                 goto done;                  goto done;
   
 found_end_int_subset:  found_end_int_subset:
                   ctxt->checkIndex = 0;
                 xmlParseInternalSubset(ctxt);                  xmlParseInternalSubset(ctxt);
                   if (ctxt->instate == XML_PARSER_EOF)
                       goto done;
                 ctxt->inSubset = 2;                  ctxt->inSubset = 2;
                 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&                  if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
                     (ctxt->sax->externalSubset != NULL))                      (ctxt->sax->externalSubset != NULL))
Line 11555  found_end_int_subset: Line 11997  found_end_int_subset:
                             ctxt->extSubSystem, ctxt->extSubURI);                              ctxt->extSubSystem, ctxt->extSubURI);
                 ctxt->inSubset = 0;                  ctxt->inSubset = 0;
                 xmlCleanSpecialAttr(ctxt);                  xmlCleanSpecialAttr(ctxt);
                   if (ctxt->instate == XML_PARSER_EOF)
                       goto done;
                 ctxt->instate = XML_PARSER_PROLOG;                  ctxt->instate = XML_PARSER_PROLOG;
                 ctxt->checkIndex = 0;                  ctxt->checkIndex = 0;
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
Line 11637  found_end_int_subset: Line 12081  found_end_int_subset:
                 break;                  break;
         }          }
     }      }
done:    done:
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
     xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret);      xmlGenericError(xmlGenericErrorContext, "PP: done %d\n", ret);
 #endif  #endif
Line 11657  encoding_error: Line 12101  encoding_error:
 }  }
   
 /**  /**
    * xmlParseCheckTransition:
    * @ctxt:  an XML parser context
    * @chunk:  a char array
    * @size:  the size in byte of the chunk
    *
    * Check depending on the current parser state if the chunk given must be
    * processed immediately or one need more data to advance on parsing.
    *
    * Returns -1 in case of error, 0 if the push is not needed and 1 if needed
    */
   static int
   xmlParseCheckTransition(xmlParserCtxtPtr ctxt, const char *chunk, int size) {
       if ((ctxt == NULL) || (chunk == NULL) || (size < 0))
           return(-1);
       if (ctxt->instate == XML_PARSER_START_TAG) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       if (ctxt->progressive == XML_PARSER_COMMENT) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       if (ctxt->instate == XML_PARSER_CDATA_SECTION) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       if (ctxt->progressive == XML_PARSER_PI) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       if (ctxt->instate == XML_PARSER_END_TAG) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       if ((ctxt->progressive == XML_PARSER_DTD) ||
           (ctxt->instate == XML_PARSER_DTD)) {
           if (memchr(chunk, '>', size) != NULL)
               return(1);
           return(0);
       }
       return(1);
   }
   
   /**
  * xmlParseChunk:   * xmlParseChunk:
  * @ctxt:  an XML parser context   * @ctxt:  an XML parser context
  * @chunk:  an char array   * @chunk:  an char array
Line 11672  xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk Line 12165  xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk
               int terminate) {                int terminate) {
     int end_in_lf = 0;      int end_in_lf = 0;
     int remain = 0;      int remain = 0;
       size_t old_avail = 0;
       size_t avail = 0;
   
     if (ctxt == NULL)      if (ctxt == NULL)
         return(XML_ERR_INTERNAL_ERROR);          return(XML_ERR_INTERNAL_ERROR);
     if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))      if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
         return(ctxt->errNo);          return(ctxt->errNo);
       if (ctxt->instate == XML_PARSER_EOF)
           return(-1);
     if (ctxt->instate == XML_PARSER_START)      if (ctxt->instate == XML_PARSER_START)
         xmlDetectSAX2(ctxt);          xmlDetectSAX2(ctxt);
     if ((size > 0) && (chunk != NULL) && (!terminate) &&      if ((size > 0) && (chunk != NULL) && (!terminate) &&
Line 11689  xmldecl_done: Line 12186  xmldecl_done:
   
     if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&      if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
         (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF))  {          (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF))  {
        int base = ctxt->input->base - ctxt->input->buf->buffer->content;        size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
        int cur = ctxt->input->cur - ctxt->input->base;        size_t cur = ctxt->input->cur - ctxt->input->base;
         int res;          int res;
   
           old_avail = xmlBufUse(ctxt->input->buf->buffer);
         /*          /*
          * Specific handling if we autodetected an encoding, we should not           * Specific handling if we autodetected an encoding, we should not
          * push more than the first line ... which depend on the encoding           * push more than the first line ... which depend on the encoding
Line 11728  xmldecl_done: Line 12226  xmldecl_done:
                 remain = 0;                  remain = 0;
             }              }
         }          }
        res =xmlParserInputBufferPush(ctxt->input->buf, size, chunk);        res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
         if (res < 0) {          if (res < 0) {
             ctxt->errNo = XML_PARSER_EOF;              ctxt->errNo = XML_PARSER_EOF;
             ctxt->disableSAX = 1;              ctxt->disableSAX = 1;
             return (XML_PARSER_EOF);              return (XML_PARSER_EOF);
         }          }
        ctxt->input->base = ctxt->input->buf->buffer->content + base;        xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
        ctxt->input->cur = ctxt->input->base + cur; 
        ctxt->input->end = 
            &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use]; 
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
         xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);          xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
 #endif  #endif
Line 11748  xmldecl_done: Line 12243  xmldecl_done:
             if ((in->encoder != NULL) && (in->buffer != NULL) &&              if ((in->encoder != NULL) && (in->buffer != NULL) &&
                     (in->raw != NULL)) {                      (in->raw != NULL)) {
                 int nbchars;                  int nbchars;
                   size_t base = xmlBufGetInputBase(in->buffer, ctxt->input);
                   size_t current = ctxt->input->cur - ctxt->input->base;
   
                nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw);                nbchars = xmlCharEncInput(in, terminate);
                 if (nbchars < 0) {                  if (nbchars < 0) {
                     /* TODO 2.6.0 */                      /* TODO 2.6.0 */
                     xmlGenericError(xmlGenericErrorContext,                      xmlGenericError(xmlGenericErrorContext,
                                     "xmlParseChunk: encoder error\n");                                      "xmlParseChunk: encoder error\n");
                     return(XML_ERR_INVALID_ENCODING);                      return(XML_ERR_INVALID_ENCODING);
                 }                  }
                   xmlBufSetInputBaseCur(in->buffer, ctxt->input, base, current);
             }              }
         }          }
     }      }
    if (remain != 0)    if (remain != 0) {
         xmlParseTryOrFinish(ctxt, 0);          xmlParseTryOrFinish(ctxt, 0);
    else    } else {
        xmlParseTryOrFinish(ctxt, terminate);        if ((ctxt->input != NULL) && (ctxt->input->buf != NULL))
             avail = xmlBufUse(ctxt->input->buf->buffer);
         /*
          * Depending on the current state it may not be such
          * a good idea to try parsing if there is nothing in the chunk
          * which would be worth doing a parser state transition and we
          * need to wait for more data
          */
         if ((terminate) || (avail > XML_MAX_TEXT_LENGTH) ||
             (old_avail == 0) || (avail == 0) ||
             (xmlParseCheckTransition(ctxt,
                        (const char *)&ctxt->input->base[old_avail],
                                      avail - old_avail)))
             xmlParseTryOrFinish(ctxt, terminate);
     }
     if (ctxt->instate == XML_PARSER_EOF)
         return(ctxt->errNo);
 
     if ((ctxt->input != NULL) &&
          (((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
          ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
         ((ctxt->options & XML_PARSE_HUGE) == 0)) {
         xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
         ctxt->instate = XML_PARSER_EOF;
     }
     if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))      if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
         return(ctxt->errNo);          return(ctxt->errNo);
   
Line 11774  xmldecl_done: Line 12296  xmldecl_done:
     }      }
     if ((end_in_lf == 1) && (ctxt->input != NULL) &&      if ((end_in_lf == 1) && (ctxt->input != NULL) &&
         (ctxt->input->buf != NULL)) {          (ctxt->input->buf != NULL)) {
           size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer,
                                            ctxt->input);
           size_t current = ctxt->input->cur - ctxt->input->base;
   
         xmlParserInputBufferPush(ctxt->input->buf, 1, "\r");          xmlParserInputBufferPush(ctxt->input->buf, 1, "\r");
   
           xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input,
                                 base, current);
     }      }
     if (terminate) {      if (terminate) {
         /*          /*
          * Check for termination           * Check for termination
          */           */
        int avail = 0;        int cur_avail = 0;
   
         if (ctxt->input != NULL) {          if (ctxt->input != NULL) {
             if (ctxt->input->buf == NULL)              if (ctxt->input->buf == NULL)
                avail = ctxt->input->length -                cur_avail = ctxt->input->length -
                        (ctxt->input->cur - ctxt->input->base);                            (ctxt->input->cur - ctxt->input->base);
             else              else
                avail = ctxt->input->buf->buffer->use -                cur_avail = xmlBufUse(ctxt->input->buf->buffer) -
                        (ctxt->input->cur - ctxt->input->base);                                      (ctxt->input->cur - ctxt->input->base);
         }          }
                            
         if ((ctxt->instate != XML_PARSER_EOF) &&          if ((ctxt->instate != XML_PARSER_EOF) &&
             (ctxt->instate != XML_PARSER_EPILOG)) {              (ctxt->instate != XML_PARSER_EPILOG)) {
             xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);              xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
        }         }
        if ((ctxt->instate == XML_PARSER_EPILOG) && (avail > 0)) {        if ((ctxt->instate == XML_PARSER_EPILOG) && (cur_avail > 0)) {
             xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);              xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
         }          }
         if (ctxt->instate != XML_PARSER_EOF) {          if (ctxt->instate != XML_PARSER_EOF) {
Line 11804  xmldecl_done: Line 12333  xmldecl_done:
         }          }
         ctxt->instate = XML_PARSER_EOF;          ctxt->instate = XML_PARSER_EOF;
     }      }
    return((xmlParserErrors) ctxt->errNo);                if (ctxt->wellFormed == 0)
         return((xmlParserErrors) ctxt->errNo);
     else
         return(0);
 }  }
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              I/O front end functions to the parser                   * *                I/O front end functions to the parser                   *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 11833  xmldecl_done: Line 12365  xmldecl_done:
  */   */
   
 xmlParserCtxtPtr  xmlParserCtxtPtr
xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
                         const char *chunk, int size, const char *filename) {                          const char *chunk, int size, const char *filename) {
     xmlParserCtxtPtr ctxt;      xmlParserCtxtPtr ctxt;
     xmlParserInputPtr inputStream;      xmlParserInputPtr inputStream;
Line 11882  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us Line 12414  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us
             memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));              memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
         if (user_data != NULL)          if (user_data != NULL)
             ctxt->userData = user_data;              ctxt->userData = user_data;
    }       }
     if (filename == NULL) {      if (filename == NULL) {
         ctxt->directory = NULL;          ctxt->directory = NULL;
     } else {      } else {
Line 11908  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us Line 12440  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us
         }          }
     }      }
     inputStream->buf = buf;      inputStream->buf = buf;
    inputStream->base = inputStream->buf->buffer->content;    xmlBufResetInput(inputStream->buf->buffer, inputStream);
    inputStream->cur = inputStream->buf->buffer->content; 
    inputStream->end =  
        &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; 
 
     inputPush(ctxt, inputStream);      inputPush(ctxt, inputStream);
   
     /*      /*
Line 11923  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us Line 12451  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us
     if ((size == 0) || (chunk == NULL)) {      if ((size == 0) || (chunk == NULL)) {
         ctxt->charset = XML_CHAR_ENCODING_NONE;          ctxt->charset = XML_CHAR_ENCODING_NONE;
     } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) {      } else if ((ctxt->input != NULL) && (ctxt->input->buf != NULL)) {
        int base = ctxt->input->base - ctxt->input->buf->buffer->content;        size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
        int cur = ctxt->input->cur - ctxt->input->base;        size_t cur = ctxt->input->cur - ctxt->input->base;
   
        xmlParserInputBufferPush(ctxt->input->buf, size, chunk);                      xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
   
        ctxt->input->base = ctxt->input->buf->buffer->content + base;        xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
        ctxt->input->cur = ctxt->input->base + cur; 
        ctxt->input->end = 
            &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer->use]; 
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
         xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);          xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
 #endif  #endif
Line 11951  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us Line 12476  xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *us
  *   *
  * Blocks further parser processing   * Blocks further parser processing
  */   */
void           void
 xmlStopParser(xmlParserCtxtPtr ctxt) {  xmlStopParser(xmlParserCtxtPtr ctxt) {
     if (ctxt == NULL)      if (ctxt == NULL)
         return;          return;
     ctxt->instate = XML_PARSER_EOF;      ctxt->instate = XML_PARSER_EOF;
       ctxt->errNo = XML_ERR_USER_STOP;
     ctxt->disableSAX = 1;      ctxt->disableSAX = 1;
     if (ctxt->input != NULL) {      if (ctxt->input != NULL) {
         ctxt->input->cur = BAD_CAST"";          ctxt->input->cur = BAD_CAST"";
Line 12032  xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user Line 12558  xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user
 #ifdef LIBXML_VALID_ENABLED  #ifdef LIBXML_VALID_ENABLED
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Front ends when parsing a DTD                           * *                Front ends when parsing a DTD                           *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 12043  xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user Line 12569  xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user
  * @enc:  the charset encoding if known   * @enc:  the charset encoding if known
  *   *
  * Load and parse a DTD   * Load and parse a DTD
 *  *
  * Returns the resulting xmlDtdPtr or NULL in case of error.   * Returns the resulting xmlDtdPtr or NULL in case of error.
  * @input will be freed by the function in any case.   * @input will be freed by the function in any case.
  */   */
Line 12068  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff Line 12594  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff
     /*      /*
      * Set-up the SAX context       * Set-up the SAX context
      */       */
    if (sax != NULL) {     if (sax != NULL) {
         if (ctxt->sax != NULL)          if (ctxt->sax != NULL)
             xmlFree(ctxt->sax);              xmlFree(ctxt->sax);
         ctxt->sax = sax;          ctxt->sax = sax;
Line 12122  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff Line 12648  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff
   
     if ((enc == XML_CHAR_ENCODING_NONE) &&      if ((enc == XML_CHAR_ENCODING_NONE) &&
         ((ctxt->input->end - ctxt->input->cur) >= 4)) {          ((ctxt->input->end - ctxt->input->cur) >= 4)) {
        /*         /*
          * Get the 4 first bytes and decode the charset           * Get the 4 first bytes and decode the charset
          * if enc != XML_CHAR_ENCODING_NONE           * if enc != XML_CHAR_ENCODING_NONE
          * plug some encoding conversion routines.           * plug some encoding conversion routines.
Line 12161  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff Line 12687  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff
     }      }
     if (sax != NULL) ctxt->sax = NULL;      if (sax != NULL) ctxt->sax = NULL;
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
    
     return(ret);      return(ret);
 }  }
   
Line 12172  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff Line 12698  xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBuff
  * @SystemID:  a NAME* containing the URL to the DTD   * @SystemID:  a NAME* containing the URL to the DTD
  *   *
  * Load and parse an external subset.   * Load and parse an external subset.
 *  *
  * Returns the resulting xmlDtdPtr or NULL in case of error.   * Returns the resulting xmlDtdPtr or NULL in case of error.
  */   */
   
Line 12195  xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *Ex Line 12721  xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *Ex
     /*      /*
      * Set-up the SAX context       * Set-up the SAX context
      */       */
    if (sax != NULL) {     if (sax != NULL) {
         if (ctxt->sax != NULL)          if (ctxt->sax != NULL)
             xmlFree(ctxt->sax);              xmlFree(ctxt->sax);
         ctxt->sax = sax;          ctxt->sax = sax;
         ctxt->userData = ctxt;          ctxt->userData = ctxt;
     }      }
    
     /*      /*
      * Canonicalise the system ID       * Canonicalise the system ID
      */       */
Line 12312  xmlParseDTD(const xmlChar *ExternalID, const xmlChar * Line 12838  xmlParseDTD(const xmlChar *ExternalID, const xmlChar *
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Front ends when parsing an Entity                       * *                Front ends when parsing an Entity                       *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 12428  xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const Line 12954  xmlParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const
          */           */
         if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) &&          if ((xmlStrEqual(ctx->version, BAD_CAST "1.0")) &&
             (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) {              (!xmlStrEqual(ctxt->input->version, BAD_CAST "1.0"))) {
            xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH,             xmlFatalErrMsg(ctxt, XML_ERR_VERSION_MISMATCH,
                            "Version mismatch between document and entity\n");                             "Version mismatch between document and entity\n");
         }          }
     }      }
Line 12711  xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParser Line 13237  xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParser
     if (ctxt->lastError.code != XML_ERR_OK)      if (ctxt->lastError.code != XML_ERR_OK)
         xmlCopyError(&ctxt->lastError, &oldctxt->lastError);          xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
   
    if (sax != NULL)     if (sax != NULL)
         ctxt->sax = oldsax;          ctxt->sax = oldsax;
     oldctxt->node_seq.maximum = ctxt->node_seq.maximum;      oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
     oldctxt->node_seq.length = ctxt->node_seq.length;      oldctxt->node_seq.length = ctxt->node_seq.length;
Line 13530  xmlCreateEntityParserCtxt(const xmlChar *URL, const xm Line 14056  xmlCreateEntityParserCtxt(const xmlChar *URL, const xm
  * @filename:  the filename or URL   * @filename:  the filename or URL
  * @options:  a combination of xmlParserOption   * @options:  a combination of xmlParserOption
  *   *
 * Create a parser context for a file or URL content.  * Create a parser context for a file or URL content.
  * Automatic support for ZLIB/Compress compressed document is provided   * Automatic support for ZLIB/Compress compressed document is provided
  * by default if found at compile-time and for file accesses   * by default if found at compile-time and for file accesses
  *   *
Line 13572  xmlCreateURLParserCtxt(const char *filename, int optio Line 14098  xmlCreateURLParserCtxt(const char *filename, int optio
  * xmlCreateFileParserCtxt:   * xmlCreateFileParserCtxt:
  * @filename:  the filename   * @filename:  the filename
  *   *
 * Create a parser context for a file content.  * Create a parser context for a file content.
  * Automatic support for ZLIB/Compress compressed document is provided   * Automatic support for ZLIB/Compress compressed document is provided
  * by default if found at compile-time.   * by default if found at compile-time.
  *   *
Line 13650  xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const ch Line 14176  xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const ch
     if (sax != NULL)      if (sax != NULL)
         ctxt->sax = NULL;          ctxt->sax = NULL;
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
    
     return(ret);      return(ret);
 }  }
   
Line 13750  xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const x Line 14276  xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const x
         xmlClearParserCtxt(ctxt);          xmlClearParserCtxt(ctxt);
         return;          return;
     }      }
  
     xmlClearParserCtxt(ctxt);      xmlClearParserCtxt(ctxt);
     if (filename != NULL)      if (filename != NULL)
         input->filename = (char *) xmlCanonicPath((const xmlChar *)filename);          input->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
Line 13768  xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const x Line 14294  xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const x
  *   *
  * parse an XML file and call the given SAX handler routines.   * parse an XML file and call the given SAX handler routines.
  * Automatic support for ZLIB/Compress compressed document is provided   * Automatic support for ZLIB/Compress compressed document is provided
 *  *
  * Returns 0 in case of success or a error number otherwise   * Returns 0 in case of success or a error number otherwise
  */   */
 int  int
Line 13776  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d Line 14302  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d
                     const char *filename) {                      const char *filename) {
     int ret = 0;      int ret = 0;
     xmlParserCtxtPtr ctxt;      xmlParserCtxtPtr ctxt;
    
     ctxt = xmlCreateFileParserCtxt(filename);      ctxt = xmlCreateFileParserCtxt(filename);
     if (ctxt == NULL) return -1;      if (ctxt == NULL) return -1;
     if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)      if (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler)
Line 13786  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d Line 14312  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d
   
     if (user_data != NULL)      if (user_data != NULL)
         ctxt->userData = user_data;          ctxt->userData = user_data;
    
     xmlParseDocument(ctxt);      xmlParseDocument(ctxt);
    
     if (ctxt->wellFormed)      if (ctxt->wellFormed)
         ret = 0;          ret = 0;
     else {      else {
Line 13804  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d Line 14330  xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_d
         ctxt->myDoc = NULL;          ctxt->myDoc = NULL;
     }      }
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
    
     return ret;      return ret;
 }  }
 #endif /* LIBXML_SAX1_ENABLED */  #endif /* LIBXML_SAX1_ENABLED */
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *              Front ends when parsing from memory                     * *                Front ends when parsing from memory                     *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 13855  xmlCreateMemoryParserCtxt(const char *buffer, int size Line 14381  xmlCreateMemoryParserCtxt(const char *buffer, int size
   
     input->filename = NULL;      input->filename = NULL;
     input->buf = buf;      input->buf = buf;
    input->base = input->buf->buffer->content;    xmlBufResetInput(input->buf->buffer, input);
    input->cur = input->buf->buffer->content; 
    input->end = &input->buf->buffer->content[input->buf->buffer->use]; 
   
     inputPush(ctxt, input);      inputPush(ctxt, input);
     return(ctxt);      return(ctxt);
Line 13913  xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const  Line 14437  xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const 
        xmlFreeDoc(ctxt->myDoc);         xmlFreeDoc(ctxt->myDoc);
        ctxt->myDoc = NULL;         ctxt->myDoc = NULL;
     }      }
    if (sax != NULL)     if (sax != NULL)
         ctxt->sax = NULL;          ctxt->sax = NULL;
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
   
Line 13931  xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const  Line 14455  xmlSAXParseMemoryWithData(xmlSAXHandlerPtr sax, const 
  * parse an XML in-memory block and use the given SAX function block   * parse an XML in-memory block and use the given SAX function block
  * to handle the parsing callback. If sax is NULL, fallback to the default   * to handle the parsing callback. If sax is NULL, fallback to the default
  * DOM tree building routines.   * DOM tree building routines.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 13946  xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *bu Line 14470  xmlSAXParseMemory(xmlSAXHandlerPtr sax, const char *bu
  * @size:  the size of the array   * @size:  the size of the array
  *   *
  * parse an XML in-memory block and build a tree.   * parse an XML in-memory block and build a tree.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
   
Line 14000  int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void * Line 14524  int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *
         ctxt->userData = user_data;          ctxt->userData = user_data;
   
     xmlParseDocument(ctxt);      xmlParseDocument(ctxt);
    
     if (ctxt->wellFormed)      if (ctxt->wellFormed)
         ret = 0;          ret = 0;
     else {      else {
Line 14016  int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void * Line 14540  int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *
         ctxt->myDoc = NULL;          ctxt->myDoc = NULL;
     }      }
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
    
     return ret;      return ret;
 }  }
 #endif /* LIBXML_SAX1_ENABLED */  #endif /* LIBXML_SAX1_ENABLED */
Line 14050  xmlCreateDocParserCtxt(const xmlChar *cur) { Line 14574  xmlCreateDocParserCtxt(const xmlChar *cur) {
  * parse an XML in-memory document and build a tree.   * parse an XML in-memory document and build a tree.
  * It use the given SAX function block to handle the parsing callback.   * It use the given SAX function block to handle the parsing callback.
  * If sax is NULL, fallback to the default DOM tree building routines.   * If sax is NULL, fallback to the default DOM tree building routines.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
   
Line 14065  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu Line 14589  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu
   
     ctxt = xmlCreateDocParserCtxt(cur);      ctxt = xmlCreateDocParserCtxt(cur);
     if (ctxt == NULL) return(NULL);      if (ctxt == NULL) return(NULL);
    if (sax != NULL) {     if (sax != NULL) {
         oldsax = ctxt->sax;          oldsax = ctxt->sax;
         ctxt->sax = sax;          ctxt->sax = sax;
         ctxt->userData = NULL;          ctxt->userData = NULL;
Line 14082  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu Line 14606  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu
     if (sax != NULL)      if (sax != NULL)
         ctxt->sax = oldsax;          ctxt->sax = oldsax;
     xmlFreeParserCtxt(ctxt);      xmlFreeParserCtxt(ctxt);
    
     return(ret);      return(ret);
 }  }
   
Line 14091  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu Line 14615  xmlSAXParseDoc(xmlSAXHandlerPtr sax, const xmlChar *cu
  * @cur:  a pointer to an array of xmlChar   * @cur:  a pointer to an array of xmlChar
  *   *
  * parse an XML in-memory document and build a tree.   * parse an XML in-memory document and build a tree.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
   
Line 14104  xmlParseDoc(const xmlChar *cur) { Line 14628  xmlParseDoc(const xmlChar *cur) {
 #ifdef LIBXML_LEGACY_ENABLED  #ifdef LIBXML_LEGACY_ENABLED
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *      Specific function to keep track of entities references          * *        Specific function to keep track of entities references          *
 *      and used by the XSLT debugger                                   * *      and used by the XSLT debugger                                   *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 14115  static xmlEntityReferenceFunc xmlEntityRefFunc = NULL; Line 14639  static xmlEntityReferenceFunc xmlEntityRefFunc = NULL;
  * xmlAddEntityReference:   * xmlAddEntityReference:
  * @ent : A valid entity   * @ent : A valid entity
  * @firstNode : A valid first node for children of entity   * @firstNode : A valid first node for children of entity
 * @lastNode : A valid last node of children entity  * @lastNode : A valid last node of children entity
  *   *
  * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY   * Notify of a reference to an entity of type XML_EXTERNAL_GENERAL_PARSED_ENTITY
  */   */
Line 14144  xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func) Line 14668  xmlSetEntityReferenceFunc(xmlEntityReferenceFunc func)
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
 *                              Miscellaneous                           * *                                Miscellaneous                           *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
Line 14260  xmlCleanupParser(void) { Line 14784  xmlCleanupParser(void) {
  * current scope   * current scope
  */   */
 #define DICT_FREE(str)                                          \  #define DICT_FREE(str)                                          \
        if ((str) && ((!dict) ||                                \        if ((str) && ((!dict) ||                                \
             (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))  \              (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))  \
             xmlFree((char *)(str));              xmlFree((char *)(str));
   
Line 14275  xmlCtxtReset(xmlParserCtxtPtr ctxt) Line 14799  xmlCtxtReset(xmlParserCtxtPtr ctxt)
 {  {
     xmlParserInputPtr input;      xmlParserInputPtr input;
     xmlDictPtr dict;      xmlDictPtr dict;
    
     if (ctxt == NULL)      if (ctxt == NULL)
         return;          return;
   
Line 14343  xmlCtxtReset(xmlParserCtxtPtr ctxt) Line 14867  xmlCtxtReset(xmlParserCtxtPtr ctxt)
     ctxt->catalogs = NULL;      ctxt->catalogs = NULL;
     ctxt->nbentities = 0;      ctxt->nbentities = 0;
     ctxt->sizeentities = 0;      ctxt->sizeentities = 0;
       ctxt->sizeentcopy = 0;
     xmlInitNodeInfoSeq(&ctxt->node_seq);      xmlInitNodeInfoSeq(&ctxt->node_seq);
   
     if (ctxt->attsDefault != NULL) {      if (ctxt->attsDefault != NULL) {
Line 14427  xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *ch Line 14952  xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *ch
         inputStream->filename = (char *)          inputStream->filename = (char *)
             xmlCanonicPath((const xmlChar *) filename);              xmlCanonicPath((const xmlChar *) filename);
     inputStream->buf = buf;      inputStream->buf = buf;
    inputStream->base = inputStream->buf->buffer->content;    xmlBufResetInput(buf->buffer, inputStream);
    inputStream->cur = inputStream->buf->buffer->content; 
    inputStream->end = 
        &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; 
   
     inputPush(ctxt, inputStream);      inputPush(ctxt, inputStream);
   
     if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&      if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
         (ctxt->input->buf != NULL)) {          (ctxt->input->buf != NULL)) {
        int base = ctxt->input->base - ctxt->input->buf->buffer->content;        size_t base = xmlBufGetInputBase(ctxt->input->buf->buffer, ctxt->input);
        int cur = ctxt->input->cur - ctxt->input->base;        size_t cur = ctxt->input->cur - ctxt->input->base;
   
         xmlParserInputBufferPush(ctxt->input->buf, size, chunk);          xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
   
        ctxt->input->base = ctxt->input->buf->buffer->content + base;        xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
        ctxt->input->cur = ctxt->input->base + cur; 
        ctxt->input->end = 
            &ctxt->input->buf->buffer->content[ctxt->input->buf->buffer-> 
                                               use]; 
 #ifdef DEBUG_PUSH  #ifdef DEBUG_PUSH
         xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);          xmlGenericError(xmlGenericErrorContext, "PP: pushed %d\n", size);
 #endif  #endif
Line 14596  xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int o Line 15114  xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int o
     if (options & XML_PARSE_HUGE) {      if (options & XML_PARSE_HUGE) {
         ctxt->options |= XML_PARSE_HUGE;          ctxt->options |= XML_PARSE_HUGE;
         options -= XML_PARSE_HUGE;          options -= XML_PARSE_HUGE;
           if (ctxt->dict != NULL)
               xmlDictSetLimit(ctxt->dict, 0);
     }      }
     if (options & XML_PARSE_OLDSAX) {      if (options & XML_PARSE_OLDSAX) {
         ctxt->options |= XML_PARSE_OLDSAX;          ctxt->options |= XML_PARSE_OLDSAX;
Line 14605  xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int o Line 15125  xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int o
         ctxt->options |= XML_PARSE_IGNORE_ENC;          ctxt->options |= XML_PARSE_IGNORE_ENC;
         options -= XML_PARSE_IGNORE_ENC;          options -= XML_PARSE_IGNORE_ENC;
     }      }
       if (options & XML_PARSE_BIG_LINES) {
           ctxt->options |= XML_PARSE_BIG_LINES;
           options -= XML_PARSE_BIG_LINES;
       }
     ctxt->linenumbers = 1;      ctxt->linenumbers = 1;
     return (options);      return (options);
 }  }
Line 14679  xmlDoRead(xmlParserCtxtPtr ctxt, const char *URL, cons Line 15203  xmlDoRead(xmlParserCtxtPtr ctxt, const char *URL, cons
  * @options:  a combination of xmlParserOption   * @options:  a combination of xmlParserOption
  *   *
  * parse an XML in-memory document and build a tree.   * parse an XML in-memory document and build a tree.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14703  xmlReadDoc(const xmlChar * cur, const char *URL, const Line 15227  xmlReadDoc(const xmlChar * cur, const char *URL, const
  * @options:  a combination of xmlParserOption   * @options:  a combination of xmlParserOption
  *   *
  * parse an XML file from the filesystem or the network.   * parse an XML file from the filesystem or the network.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14726  xmlReadFile(const char *filename, const char *encoding Line 15250  xmlReadFile(const char *filename, const char *encoding
  * @options:  a combination of xmlParserOption   * @options:  a combination of xmlParserOption
  *   *
  * parse an XML in-memory document and build a tree.   * parse an XML in-memory document and build a tree.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14750  xmlReadMemory(const char *buffer, int size, const char Line 15274  xmlReadMemory(const char *buffer, int size, const char
  * parse an XML from a file descriptor and build a tree.   * parse an XML from a file descriptor and build a tree.
  * NOTE that the file descriptor will not be closed when the   * NOTE that the file descriptor will not be closed when the
  *      reader is closed or reset.   *      reader is closed or reset.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14871  xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar *  Line 15395  xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * 
  *   *
  * parse an XML file from the filesystem or the network.   * parse an XML file from the filesystem or the network.
  * This reuses the existing @ctxt parser context   * This reuses the existing @ctxt parser context
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14906  xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *fil Line 15430  xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *fil
  *   *
  * parse an XML in-memory document and build a tree.   * parse an XML in-memory document and build a tree.
  * This reuses the existing @ctxt parser context   * This reuses the existing @ctxt parser context
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr
Line 14950  xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *b Line 15474  xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *b
  * This reuses the existing @ctxt parser context   * This reuses the existing @ctxt parser context
  * NOTE that the file descriptor will not be closed when the   * NOTE that the file descriptor will not be closed when the
  *      reader is closed or reset.   *      reader is closed or reset.
 *  *
  * Returns the resulting document tree   * Returns the resulting document tree
  */   */
 xmlDocPtr  xmlDocPtr

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>