1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
diff -urN afb/afbpixmap.c afb/afbpixmap.c
--- afb/afbpixmap.c 2005-08-26 15:35:33.000000000 -0400
+++ afb/afbpixmap.c 2005-08-26 14:09:24.000000000 -0400
@@ -77,10 +77,14 @@
int depth;
{
PixmapPtr pPixmap;
- int datasize;
- int paddedWidth;
+ size_t datasize;
+ size_t paddedWidth;
paddedWidth = BitmapBytePad(width);
+
+ if (paddedWidth > 32767 || height > 32767)
+ return NullPixmap;
+
datasize = height * paddedWidth * depth;
pPixmap = AllocatePixmap(pScreen, datasize);
if (!pPixmap)
diff -urN cfb/cfbpixmap.c cfb/cfbpixmap.c
--- cfb/cfbpixmap.c 2005-08-26 15:35:33.000000000 -0400
+++ cfb/cfbpixmap.c 2005-08-26 14:10:14.000000000 -0400
@@ -68,10 +68,14 @@
int depth;
{
PixmapPtr pPixmap;
- int datasize;
- int paddedWidth;
+ size_t datasize;
+ size_t paddedWidth;
paddedWidth = PixmapBytePad(width, depth);
+
+ if (paddedWidth > 32767 || height > 32767)
+ return NullPixmap;
+
datasize = height * paddedWidth;
pPixmap = AllocatePixmap(pScreen, datasize);
if (!pPixmap)
diff -urN dix/dispatch.c dix/dispatch.c
--- dix/dispatch.c 2004-12-12 20:23:05.000000000 -0500
+++ dix/dispatch.c 2005-08-26 14:13:37.000000000 -0400
@@ -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 compute the size in
+ * bytes of the pixmap and try 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;
diff -urN fb/fbpixmap.c fb/fbpixmap.c
--- fb/fbpixmap.c 2004-08-08 23:40:50.000000000 -0400
+++ fb/fbpixmap.c 2005-08-26 14:14:49.000000000 -0400
@@ -32,12 +32,16 @@
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 > 32767 || height > 32767)
+ return NullPixmap;
+
datasize = height * paddedWidth;
#ifdef PIXPRIV
base = pScreen->totalPixmapSize;
diff -urN hw/xfree86/xaa/xaaInit.c hw/xfree86/xaa/xaaInit.c
--- hw/xfree86/xaa/xaaInit.c 2004-07-30 16:30:56.000000000 -0400
+++ hw/xfree86/xaa/xaaInit.c 2005-08-26 14:16:30.000000000 -0400
@@ -499,6 +499,9 @@
PixmapPtr pPix = NULL;
int size = w * h;
+ if (w > 32767 || h > 32767)
+ return NullPixmap;
+
if (!infoRec->offscreenDepthsInitialized)
XAAInitializeOffscreenDepths (pScreen);
diff -urN hw/xfree86/xf4bpp/ppcPixmap.c hw/xfree86/xf4bpp/ppcPixmap.c
--- hw/xfree86/xf4bpp/ppcPixmap.c 2004-04-23 15:54:17.000000000 -0400
+++ hw/xfree86/xf4bpp/ppcPixmap.c 2005-08-26 14:17:29.000000000 -0400
@@ -85,14 +85,18 @@
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)) ;
if ( depth > 8 )
- return (PixmapPtr) NULL ;
+ return (PixmapPtr) NULL ;
+
+ if (width > 32767 || height > 32767)
+ return (PixmapPtr) NULL ;
size = PixmapBytePad(width, depth);
+
pPixmap = AllocatePixmap (pScreen, (height * size));
if ( !pPixmap )
diff -urN mfb/mfbpixmap.c mfb/mfbpixmap.c
--- mfb/mfbpixmap.c 2003-11-14 11:48:57.000000000 -0500
+++ mfb/mfbpixmap.c 2005-08-26 15:34:32.000000000 -0400
@@ -72,11 +72,15 @@
int depth;
{
PixmapPtr pPixmap;
- int datasize;
- int paddedWidth;
+ size_t datasize;
+ size_t paddedWidth;
if (depth != 1)
return NullPixmap;
+
+ if (width > 32767 || height > 32767)
+ return NullPixmap;
+
paddedWidth = BitmapBytePad(width);
datasize = height * paddedWidth;
pPixmap = AllocatePixmap(pScreen, datasize);
|