$NetBSD: patch-aj,v 1.3 2005/01/17 12:19:13 kei Exp $ --- libs/xpdf/xpdf/Catalog.cc.orig Mon Nov 4 07:15:36 2002 +++ libs/xpdf/xpdf/Catalog.cc Fri Oct 29 09:18:17 2004 @@ -22,6 +22,7 @@ #include "Error.h" #include "Link.h" #include "Catalog.h" +#include //------------------------------------------------------------------------ // Catalog @@ -63,6 +64,12 @@ } pagesSize = numPages0 = obj.getInt(); obj.free(); + if ((pagesSize >= INT_MAX / sizeof(Page *)) || + (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 @@ } if (start >= pagesSize) { pagesSize += 32; + if ((pagesSize >= INT_MAX/sizeof(Page *)) || + (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) {