NON-WORKING python with an older version of the MinGW patch.
[fedora-mingw.git] / python / python-2.5.CVE-2007-4965-int-overflow.patch
1 diff -ru Python-2.5-orig/Modules/imageop.c Python-2.5/Modules/imageop.c
2 --- Python-2.5-orig/Modules/imageop.c   2006-01-19 01:09:39.000000000 -0500
3 +++ Python-2.5/Modules/imageop.c        2007-10-19 01:11:33.000000000 -0400
4 @@ -78,7 +78,7 @@
5         char *cp, *ncp;
6         short *nsp;
7         Py_Int32 *nlp;
8 -       int len, size, x, y, newx1, newx2, newy1, newy2;
9 +       int len, size, x, y, newx1, newx2, newy1, newy2, nlen;
10         int ix, iy, xstep, ystep;
11         PyObject *rv;
12  
13 @@ -90,13 +90,19 @@
14                 PyErr_SetString(ImageopError, "Size should be 1, 2 or 4");
15                 return 0;
16         }
17 -       if ( len != size*x*y ) {
18 +       if (( len != size*x*y ) ||
19 +            ( size != ((len / x) / y) )) {
20                 PyErr_SetString(ImageopError, "String has incorrect length");
21                 return 0;
22         }
23         xstep = (newx1 < newx2)? 1 : -1;
24         ystep = (newy1 < newy2)? 1 : -1;
25      
26 +        nlen = (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size;
27 +        if ( size != ((nlen / (abs(newx2-newx1)+1)) / (abs(newy2-newy1)+1)) ) {
28 +               PyErr_SetString(ImageopError, "String has incorrect length");
29 +               return 0;
30 +       }
31         rv = PyString_FromStringAndSize(NULL,
32                              (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
33         if ( rv == 0 )
34 @@ -132,7 +138,7 @@
35         char *cp, *ncp;
36         short *nsp;
37         Py_Int32 *nlp;
38 -       int len, size, x, y, newx, newy;
39 +       int len, size, x, y, newx, newy, nlen;
40         int ix, iy;
41         int oix, oiy;
42         PyObject *rv;
43 @@ -145,12 +151,18 @@
44                 PyErr_SetString(ImageopError, "Size should be 1, 2 or 4");
45                 return 0;
46         }
47 -       if ( len != size*x*y ) {
48 +       if ( ( len != size*x*y ) ||
49 +             ( size != ((len / x) / y) ) ) {
50 +               PyErr_SetString(ImageopError, "String has incorrect length");
51 +               return 0;
52 +       }
53 +        nlen = newx*newy*size;
54 +       if ( size != ((nlen / newx) / newy) ) {
55                 PyErr_SetString(ImageopError, "String has incorrect length");
56                 return 0;
57         }
58      
59 -       rv = PyString_FromStringAndSize(NULL, newx*newy*size);
60 +       rv = PyString_FromStringAndSize(NULL, nlen);
61         if ( rv == 0 )
62                 return 0;
63         ncp = (char *)PyString_AsString(rv);
64 @@ -190,7 +202,8 @@
65                 PyErr_SetString(ImageopError, "Size should be 1 or 4");
66                 return 0;
67         }
68 -       if ( maxx*maxy*width != len ) {
69 +       if ( ( maxx*maxy*width != len ) ||
70 +             ( maxx != ((len / maxy) / width) ) ) {
71                 PyErr_SetString(ImageopError, "String has incorrect length");
72                 return 0;
73         }
74 @@ -240,7 +253,8 @@
75         if ( !PyArg_ParseTuple(args, "s#iii", &cp, &len, &x, &y, &tres) )
76                 return 0;
77  
78 -       if ( x*y != len ) {
79 +       if ( ( x*y != len ) ||
80 +             ( x != len / y ) ) {
81                 PyErr_SetString(ImageopError, "String has incorrect length");
82                 return 0;
83         }
84 @@ -281,7 +295,8 @@
85         if ( !PyArg_ParseTuple(args, "s#ii", &cp, &len, &x, &y) )
86                 return 0;
87  
88 -       if ( x*y != len ) {
89 +       if ( ( x*y != len ) ||
90 +             ( x != len / y ) ) {
91                 PyErr_SetString(ImageopError, "String has incorrect length");
92                 return 0;
93         }
94 @@ -320,7 +335,8 @@
95         if ( !PyArg_ParseTuple(args, "s#ii", &cp, &len, &x, &y) )
96                 return 0;
97  
98 -       if ( x*y != len ) {
99 +       if ( ( x*y != len ) ||
100 +             ( x != len / y ) ) {
101                 PyErr_SetString(ImageopError, "String has incorrect length");
102                 return 0;
103         }
104 @@ -358,7 +374,8 @@
105         if ( !PyArg_ParseTuple(args, "s#ii", &cp, &len, &x, &y) )
106                 return 0;
107  
108 -       if ( x*y != len ) {
109 +       if ( ( x*y != len ) ||
110 +             ( x != len / y ) ) {
111                 PyErr_SetString(ImageopError, "String has incorrect length");
112                 return 0;
113         }
114 @@ -404,7 +421,8 @@
115         if ( !PyArg_ParseTuple(args, "s#ii", &cp, &len, &x, &y) )
116                 return 0;
117  
118 -       if ( x*y != len ) {
119 +       if ( ( x*y != len ) ||
120 +             ( x != len / y ) ) {
121                 PyErr_SetString(ImageopError, "String has incorrect length");
122                 return 0;
123         }
124 @@ -443,7 +461,11 @@
125         if ( !PyArg_ParseTuple(args, "s#iiii", &cp, &len, &x, &y, &v0, &v1) )
126                 return 0;
127  
128 -       nlen = x*y;
129 +        nlen = x*y;
130 +       if ( x != (nlen / y) ) {
131 +               PyErr_SetString(ImageopError, "String has incorrect length");
132 +               return 0;
133 +       }
134         if ( (nlen+7)/8 != len ) {
135                 PyErr_SetString(ImageopError, "String has incorrect length");
136                 return 0;
137 @@ -481,6 +503,10 @@
138                 return 0;
139  
140         nlen = x*y;
141 +       if ( x != (nlen / y) ) {
142 +               PyErr_SetString(ImageopError, "String has incorrect length");
143 +               return 0;
144 +       }
145         if ( (nlen+3)/4 != len ) {
146                 PyErr_SetString(ImageopError, "String has incorrect length");
147                 return 0;
148 @@ -517,6 +543,10 @@
149                 return 0;
150  
151         nlen = x*y;
152 +       if ( x != (nlen / y) ) {
153 +               PyErr_SetString(ImageopError, "String has incorrect length");
154 +               return 0;
155 +       }
156         if ( (nlen+1)/2 != len ) {
157                 PyErr_SetString(ImageopError, "String has incorrect length");
158                 return 0;
159 @@ -554,6 +584,10 @@
160                 return 0;
161  
162         nlen = x*y;
163 +       if ( x != (nlen / y) ) {
164 +               PyErr_SetString(ImageopError, "String has incorrect length");
165 +               return 0;
166 +       }
167         if ( nlen*4 != len ) {
168                 PyErr_SetString(ImageopError, "String has incorrect length");
169                 return 0;
170 @@ -598,6 +632,10 @@
171                 return 0;
172  
173         nlen = x*y;
174 +       if ( x != (nlen / y) ) {
175 +               PyErr_SetString(ImageopError, "String has incorrect length");
176 +               return 0;
177 +       }
178         if ( nlen != len ) {
179                 PyErr_SetString(ImageopError, "String has incorrect length");
180                 return 0;
181 @@ -648,6 +686,10 @@
182                 return 0;
183  
184         nlen = x*y;
185 +       if ( x != (nlen / y) ) {
186 +               PyErr_SetString(ImageopError, "String has incorrect length");
187 +               return 0;
188 +       }
189         if ( nlen*4 != len ) {
190                 PyErr_SetString(ImageopError, "String has incorrect length");
191                 return 0;
192 @@ -693,6 +735,10 @@
193                 return 0;
194  
195         nlen = x*y;
196 +       if ( x != (nlen / y) ) {
197 +               PyErr_SetString(ImageopError, "String has incorrect length");
198 +               return 0;
199 +       }
200         if ( nlen != len ) {
201                 PyErr_SetString(ImageopError, "String has incorrect length");
202                 return 0;
203 Only in Python-2.5/Modules: imageop.c~
204 Only in Python-2.5/Modules: imageop.c.cve2007-4965
205 diff -ru Python-2.5-orig/Modules/rgbimgmodule.c Python-2.5/Modules/rgbimgmodule.c
206 --- Python-2.5-orig/Modules/rgbimgmodule.c      2006-08-11 23:18:50.000000000 -0400
207 +++ Python-2.5/Modules/rgbimgmodule.c   2007-10-19 01:05:44.000000000 -0400
208 @@ -299,6 +299,11 @@
209         xsize = image.xsize;
210         ysize = image.ysize;
211         zsize = image.zsize;
212 +       tablen = xsize * ysize * zsize * sizeof(Py_Int32);
213 +        if (xsize != (((tablen / ysize) / zsize) / sizeof(Py_Int32))) {
214 +               PyErr_NoMemory();
215 +               goto finally;
216 +        }
217         if (rle) {
218                 tablen = ysize * zsize * sizeof(Py_Int32);
219                 starttab = (Py_Int32 *)malloc(tablen);
220 Only in Python-2.5/Modules: rgbimgmodule.c.cve2007-4965
221 Only in Python-2.5/Modules: _tkinter.c.tkinter