--- kdegraphics/kpdf/xpdf/Catalog.cc 2003/08/20 21:25:12 1.3 +++ kdegraphics/kpdf/xpdf/Catalog.cc 2004/10/28 09:25:05 1.3.2.3 @@ -12,6 +12,7 @@ #pragma implementation #endif +#include #include #include "gmem.h" #include "Object.h" @@ -63,6 +64,12 @@ Catalog::Catalog(XRef *xrefA) { } pagesSize = numPages0 = obj.getInt(); obj.free(); + if ((unsigned) pagesSize >= INT_MAX / sizeof(Page *) || + (unsigned) pagesSize >= INT_MAX / sizeof(Ref)) { + error(-1, "Invalid 'pagesSize'"); + ok = gFalse; + return; + } pages = (Page **)gmalloc(pagesSize * sizeof(Page *)); pageRefs = (Ref *)gmalloc(pagesSize * sizeof(Ref)); for (i = 0; i < pagesSize; ++i) { @@ -190,6 +197,11 @@ int Catalog::readPageTree(Dict *pagesDic } if (start >= pagesSize) { pagesSize += 32; + if ((unsigned) pagesSize >= INT_MAX / sizeof(Page *) || + (unsigned) pagesSize >= INT_MAX / sizeof(Ref)) { + error(-1, "Invalid 'pagesSize' parameter."); + goto err3; + } pages = (Page **)grealloc(pages, pagesSize * sizeof(Page *)); pageRefs = (Ref *)grealloc(pageRefs, pagesSize * sizeof(Ref)); for (j = pagesSize - 32; j < pagesSize; ++j) { --- kdegraphics/kpdf/xpdf/XRef.cc 2003/08/20 21:25:12 1.3 +++ kdegraphics/kpdf/xpdf/XRef.cc 2004/10/28 09:35:21 1.3.2.4 @@ -12,6 +12,7 @@ #pragma implementation #endif +#include #include #include #include @@ -76,6 +77,12 @@ XRef::XRef(BaseStream *strA, GString *ow // trailer is ok - read the xref table } else { + if ((unsigned) size >= INT_MAX / sizeof(XRefEntry)) { + error(-1, "Invalid 'size' inside xref table."); + ok = gFalse; + errCode = errDamaged; + return; + } entries = (XRefEntry *)gmalloc(size * sizeof(XRefEntry)); for (i = 0; i < size; ++i) { entries[i].offset = 0xffffffff; @@ -267,6 +274,10 @@ GBool XRef::readXRef(Guint *pos) { // table size if (first + n > size) { newSize = size + 256; + if ((unsigned) newSize >= INT_MAX / sizeof(XRefEntry)) { + error(-1, "Invalid 'newSize'"); + goto err2; + } entries = (XRefEntry *)grealloc(entries, newSize * sizeof(XRefEntry)); for (i = size; i < newSize; ++i) { entries[i].offset = 0xffffffff; @@ -415,6 +426,10 @@ GBool XRef::constructXRef() { if (!strncmp(p, "obj", 3)) { if (num >= size) { newSize = (num + 1 + 255) & ~255; + if ((unsigned) newSize >= INT_MAX / sizeof(XRefEntry)) { + error(-1, "Invalid 'obj' parameters."); + return gFalse; + } entries = (XRefEntry *) grealloc(entries, newSize * sizeof(XRefEntry)); for (i = size; i < newSize; ++i) { @@ -436,6 +451,11 @@ GBool XRef::constructXRef() { } else if (!strncmp(p, "endstream", 9)) { if (streamEndsLen == streamEndsSize) { streamEndsSize += 64; + if ((unsigned) streamEndsSize >= INT_MAX / sizeof(int)) { + error(-1, "Invalid 'endstream' parameter."); + return gFalse; + } + streamEnds = (Guint *)grealloc(streamEnds, streamEndsSize * sizeof(int)); }