@@ -186,7 +186,7 @@ w_object(PyObject *v, WFILE *p)
186186 n = strlen (buf );
187187 w_byte (TYPE_FLOAT , p );
188188 w_byte ((int )n , p );
189- w_string (buf , n , p );
189+ w_string (buf , ( int ) n , p );
190190 }
191191 }
192192#ifndef WITHOUT_COMPLEX
@@ -215,16 +215,16 @@ w_object(PyObject *v, WFILE *p)
215215 PyComplex_RealAsDouble (v ));
216216 PyFloat_AsReprString (buf , temp );
217217 Py_DECREF (temp );
218- n = ( int ) strlen (buf );
219- w_byte (n , p );
220- w_string (buf , n , p );
218+ n = strlen (buf );
219+ w_byte (( int ) n , p );
220+ w_string (buf , ( int ) n , p );
221221 temp = (PyFloatObject * )PyFloat_FromDouble (
222222 PyComplex_ImagAsDouble (v ));
223223 PyFloat_AsReprString (buf , temp );
224224 Py_DECREF (temp );
225- n = ( int ) strlen (buf );
226- w_byte (n , p );
227- w_string (buf , n , p );
225+ n = strlen (buf );
226+ w_byte (( int ) n , p );
227+ w_string (buf , ( int ) n , p );
228228 }
229229 }
230230#endif
@@ -248,8 +248,14 @@ w_object(PyObject *v, WFILE *p)
248248 w_byte (TYPE_STRING , p );
249249 }
250250 n = PyString_GET_SIZE (v );
251+ if (n > INT_MAX ) {
252+ /* huge strings are not supported */
253+ p -> depth -- ;
254+ p -> error = 1 ;
255+ return ;
256+ }
251257 w_long ((long )n , p );
252- w_string (PyString_AS_STRING (v ), n , p );
258+ w_string (PyString_AS_STRING (v ), ( int ) n , p );
253259 }
254260#ifdef Py_USING_UNICODE
255261 else if (PyUnicode_Check (v )) {
@@ -262,8 +268,13 @@ w_object(PyObject *v, WFILE *p)
262268 }
263269 w_byte (TYPE_UNICODE , p );
264270 n = PyString_GET_SIZE (utf8 );
271+ if (n > INT_MAX ) {
272+ p -> depth -- ;
273+ p -> error = 1 ;
274+ return ;
275+ }
265276 w_long ((long )n , p );
266- w_string (PyString_AS_STRING (utf8 ), n , p );
277+ w_string (PyString_AS_STRING (utf8 ), ( int ) n , p );
267278 Py_DECREF (utf8 );
268279 }
269280#endif
@@ -350,8 +361,13 @@ w_object(PyObject *v, WFILE *p)
350361 PyBufferProcs * pb = v -> ob_type -> tp_as_buffer ;
351362 w_byte (TYPE_STRING , p );
352363 n = (* pb -> bf_getreadbuffer )(v , 0 , (void * * )& s );
364+ if (n > INT_MAX ) {
365+ p -> depth -- ;
366+ p -> error = 1 ;
367+ return ;
368+ }
353369 w_long ((long )n , p );
354- w_string (s , n , p );
370+ w_string (s , ( int ) n , p );
355371 }
356372 else {
357373 w_byte (TYPE_UNKNOWN , p );
0 commit comments