--- ./programs/Xserver/hw/xfree86/xaa/xaaInit.c.orig 2004-07-30 13:30:56.000000000 -0700 +++ ./programs/Xserver/hw/xfree86/xaa/xaaInit.c 2005-09-25 17:15:50.000000000 -0700 @@ -498,6 +498,9 @@ XAAPixmapPtr pPriv; PixmapPtr pPix = NULL; int size = w * h; + + if (w > 32767 || h > 32767) + return NullPixmap; if (!infoRec->offscreenDepthsInitialized) XAAInitializeOffscreenDepths (pScreen); --- ./programs/Xserver/hw/xfree86/xf4bpp/ppcPixmap.c.orig 2004-04-23 12:54:17.000000000 -0700 +++ ./programs/Xserver/hw/xfree86/xf4bpp/ppcPixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -85,7 +85,7 @@ int depth ; { register PixmapPtr pPixmap = (PixmapPtr)NULL; - int size ; + size_t size ; TRACE(("xf4bppCreatePixmap(pScreen=0x%x, width=%d, height=%d, depth=%d)\n", pScreen, width, height, depth)) ; @@ -93,6 +93,10 @@ return (PixmapPtr) NULL ; size = PixmapBytePad(width, depth); + + if (size / 4 > 32767 || height > 32767) + return (PixmapPtr) NULL ; + pPixmap = AllocatePixmap (pScreen, (height * size)); if ( !pPixmap ) --- ./programs/Xserver/afb/afbpixmap.c.orig 2004-04-23 11:59:39.000000000 -0700 +++ ./programs/Xserver/afb/afbpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -73,10 +73,14 @@ int depth; { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; paddedWidth = BitmapBytePad(width); + + if (paddedWidth > 32767 || height > 32767 || depth > 4) + return NullPixmap; + datasize = height * paddedWidth * depth; pPixmap = AllocatePixmap(pScreen, datasize); if (!pPixmap) --- ./programs/Xserver/mfb/mfbpixmap.c.orig 2003-11-14 08:48:57.000000000 -0800 +++ ./programs/Xserver/mfb/mfbpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -72,12 +72,14 @@ int depth; { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; if (depth != 1) return NullPixmap; paddedWidth = BitmapBytePad(width); + if (paddedWidth / 4 > 32767 || height > 32767) + return NullPixmap; datasize = height * paddedWidth; pPixmap = AllocatePixmap(pScreen, datasize); if (!pPixmap) --- ./programs/Xserver/dix/dispatch.c.orig 2004-12-12 17:23:05.000000000 -0800 +++ ./programs/Xserver/dix/dispatch.c 2005-09-25 17:15:50.000000000 -0700 @@ -1506,6 +1506,23 @@ client->errorValue = 0; return BadValue; } + if (stuff->width > 32767 || stuff->height > 32767) + { + /* It is allowed to try and allocate a pixmap which is larger than + * 32767 in either dimension. However, all of the framebuffer code + * is buggy and does not reliably draw to such big pixmaps, basically + * because the Region data structure operates with signed shorts + * for the rectangles in it. + * + * Furthermore, several places in the X server computes the + * size in bytes of the pixmap and tries to store it in an + * integer. This integer can overflow and cause the allocated size + * to be much smaller. + * + * So, such big pixmaps are rejected here with a BadAlloc + */ + return BadAlloc; + } if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; --- ./programs/Xserver/dix/pixmap.c.orig 2004-04-23 12:04:44.000000000 -0700 +++ ./programs/Xserver/dix/pixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -126,6 +126,9 @@ unsigned size; int i; + if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize) + return NullPixmap; + pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize); if (!pPixmap) return NullPixmap; --- ./programs/Xserver/fb/fbpixmap.c.orig 2004-08-08 20:40:50.000000000 -0700 +++ ./programs/Xserver/fb/fbpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -32,12 +32,14 @@ fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp) { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; int adjust; int base; paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits); + if (paddedWidth / 4 > 32767 || height > 32767) + return NullPixmap; datasize = height * paddedWidth; #ifdef PIXPRIV base = pScreen->totalPixmapSize; --- ./programs/Xserver/iplan2p4/iplpixmap.c.orig 2004-04-23 12:54:24.000000000 -0700 +++ ./programs/Xserver/iplan2p4/iplpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -74,12 +74,14 @@ int depth; { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; int ipad=INTER_PLANES*2 - 1; paddedWidth = PixmapBytePad(width, depth); paddedWidth = (paddedWidth + ipad) & ~ipad; + if (paddedWidth / 4 > 32767 || height > 32767) + return NullPixmap; datasize = height * paddedWidth; pPixmap = AllocatePixmap(pScreen, datasize); if (!pPixmap) --- ./programs/Xserver/cfb/cfbpixmap.c.orig 2004-04-23 12:00:12.000000000 -0700 +++ ./programs/Xserver/cfb/cfbpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -70,10 +70,13 @@ int depth; { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; paddedWidth = PixmapBytePad(width, depth); + + if (paddedWidth / 4 > 32767 || height > 32767) + return NullPixmap; datasize = height * paddedWidth; pPixmap = AllocatePixmap(pScreen, datasize); if (!pPixmap) --- ./programs/Xserver/ilbm/ilbmpixmap.c.orig 2004-04-23 12:54:22.000000000 -0700 +++ ./programs/Xserver/ilbm/ilbmpixmap.c 2005-09-25 17:15:50.000000000 -0700 @@ -75,10 +75,12 @@ int depth; { PixmapPtr pPixmap; - int datasize; - int paddedWidth; + size_t datasize; + size_t paddedWidth; paddedWidth = BitmapBytePad(width); + if (paddedWidth > 32767 || height > 32767 || depth > 4) + return NullPixmap; datasize = height * paddedWidth * depth; pPixmap = AllocatePixmap(pScreen, datasize); if (!pPixmap)