--- SAX2.c.orig 2008-10-31 13:57:32.000000000 -0700 +++ SAX2.c 2008-10-31 19:06:26.000000000 -0700 @@ -11,6 +11,7 @@ #include "libxml.h" #include #include +#include #include #include #include @@ -2455,9 +2456,14 @@ (xmlDictOwns(ctxt->dict, lastChild->content))) { lastChild->content = xmlStrdup(lastChild->content); } + if ((size_t)ctxt->nodelen > SIZE_T_MAX - (size_t)len || + (size_t)ctxt->nodemem + (size_t)len > SIZE_T_MAX / 2) { + xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters overflow prevented"); + return; + } if (ctxt->nodelen + len >= ctxt->nodemem) { xmlChar *newbuf; - int size; + size_t size; size = ctxt->nodemem + len; size *= 2;