diff --git a/parser.c b/parser.c index 8d263358..ae8f9efa 100644 --- a/parser.c +++ b/parser.c @@ -7850,12 +7850,20 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) return; } + if (ctxt->input_id >= INT_MAX) { + xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, + "Input ID overflow\n"); + return; + } + input = xmlNewEntityInputStream(ctxt, entity); if (xmlPushInput(ctxt, input) < 0) { xmlFreeInputStream(input); return; } + input->id = ++ctxt->input_id; + entity->flags |= XML_ENT_EXPANDING; if (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) { diff --git a/parserInternals.c b/parserInternals.c index 86c5304f..c6549e3b 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1509,19 +1509,6 @@ xmlNewInputStream(xmlParserCtxtPtr ctxt) { input->line = 1; input->col = 1; - /* - * If the context is NULL the id cannot be initialized, but that - * should not happen while parsing which is the situation where - * the id is actually needed. - */ - if (ctxt != NULL) { - if (input->id >= INT_MAX) { - xmlCtxtErrMemory(ctxt); - return(NULL); - } - input->id = ctxt->input_id++; - } - return(input); }