Lines 186-191
PyUnicodeObject *_PyUnicode_New(int leng
Link Here
|
186 |
return unicode_empty; |
186 |
return unicode_empty; |
187 |
} |
187 |
} |
188 |
|
188 |
|
|
|
189 |
/* Ensure we won't overflow the size. */ |
190 |
if (length > ((INT_MAX / sizeof(Py_UNICODE)) - 1)) { |
191 |
return (PyUnicodeObject *)PyErr_NoMemory(); |
192 |
} |
193 |
|
189 |
/* Unicode freelist & memory allocation */ |
194 |
/* Unicode freelist & memory allocation */ |
190 |
if (unicode_freelist) { |
195 |
if (unicode_freelist) { |
191 |
unicode = unicode_freelist; |
196 |
unicode = unicode_freelist; |
Lines 1040-1045
PyObject *PyUnicode_EncodeUTF7(const Py_
Link Here
|
1040 |
char * out; |
1045 |
char * out; |
1041 |
char * start; |
1046 |
char * start; |
1042 |
|
1047 |
|
|
|
1048 |
if (cbAllocated / 5 != size) |
1049 |
return PyErr_NoMemory(); |
1050 |
|
1043 |
if (size == 0) |
1051 |
if (size == 0) |
1044 |
return PyString_FromStringAndSize(NULL, 0); |
1052 |
return PyString_FromStringAndSize(NULL, 0); |
1045 |
|
1053 |
|
Lines 1638-1643
PyUnicode_EncodeUTF16(const Py_UNICODE *
Link Here
|
1638 |
{ |
1646 |
{ |
1639 |
PyObject *v; |
1647 |
PyObject *v; |
1640 |
unsigned char *p; |
1648 |
unsigned char *p; |
|
|
1649 |
int nsize, bytesize; |
1641 |
#ifdef Py_UNICODE_WIDE |
1650 |
#ifdef Py_UNICODE_WIDE |
1642 |
int i, pairs; |
1651 |
int i, pairs; |
1643 |
#else |
1652 |
#else |
Lines 1662-1669
PyUnicode_EncodeUTF16(const Py_UNICODE *
Link Here
|
1662 |
if (s[i] >= 0x10000) |
1671 |
if (s[i] >= 0x10000) |
1663 |
pairs++; |
1672 |
pairs++; |
1664 |
#endif |
1673 |
#endif |
1665 |
v = PyString_FromStringAndSize(NULL, |
1674 |
/* 2 * (size + pairs + (byteorder == 0)) */ |
1666 |
2 * (size + pairs + (byteorder == 0))); |
1675 |
if (size > INT_MAX || |
|
|
1676 |
size > INT_MAX - pairs - (byteorder == 0)) |
1677 |
return PyErr_NoMemory(); |
1678 |
nsize = (size + pairs + (byteorder == 0)); |
1679 |
bytesize = nsize * 2; |
1680 |
if (bytesize / 2 != nsize) |
1681 |
return PyErr_NoMemory(); |
1682 |
v = PyString_FromStringAndSize(NULL, bytesize); |
1667 |
if (v == NULL) |
1683 |
if (v == NULL) |
1668 |
return NULL; |
1684 |
return NULL; |
1669 |
|
1685 |
|
Lines 1977-1982
PyObject *unicodeescape_string(const Py_
Link Here
|
1977 |
char *p; |
1993 |
char *p; |
1978 |
|
1994 |
|
1979 |
static const char *hexdigit = "0123456789abcdef"; |
1995 |
static const char *hexdigit = "0123456789abcdef"; |
|
|
1996 |
#ifdef Py_UNICODE_WIDE |
1997 |
const int expandsize = 10; |
1998 |
#else |
1999 |
const int expandsize = 6; |
2000 |
#endif |
1980 |
|
2001 |
|
1981 |
/* Initial allocation is based on the longest-possible unichr |
2002 |
/* Initial allocation is based on the longest-possible unichr |
1982 |
escape. |
2003 |
escape. |
Lines 1992-2004
PyObject *unicodeescape_string(const Py_
Link Here
|
1992 |
escape. |
2013 |
escape. |
1993 |
*/ |
2014 |
*/ |
1994 |
|
2015 |
|
|
|
2016 |
if (size > (INT_MAX - 2 - 1) / expandsize) |
2017 |
return PyErr_NoMemory(); |
2018 |
|
1995 |
repr = PyString_FromStringAndSize(NULL, |
2019 |
repr = PyString_FromStringAndSize(NULL, |
1996 |
2 |
2020 |
2 |
1997 |
#ifdef Py_UNICODE_WIDE |
2021 |
+ expandsize*size |
1998 |
+ 10*size |
|
|
1999 |
#else |
2000 |
+ 6*size |
2001 |
#endif |
2002 |
+ 1); |
2022 |
+ 1); |
2003 |
if (repr == NULL) |
2023 |
if (repr == NULL) |
2004 |
return NULL; |
2024 |
return NULL; |
Lines 2239-2250
PyObject *PyUnicode_EncodeRawUnicodeEsca
Link Here
|
2239 |
char *q; |
2259 |
char *q; |
2240 |
|
2260 |
|
2241 |
static const char *hexdigit = "0123456789abcdef"; |
2261 |
static const char *hexdigit = "0123456789abcdef"; |
2242 |
|
|
|
2243 |
#ifdef Py_UNICODE_WIDE |
2262 |
#ifdef Py_UNICODE_WIDE |
2244 |
repr = PyString_FromStringAndSize(NULL, 10 * size); |
2263 |
const int expandsize = 10; |
2245 |
#else |
2264 |
#else |
2246 |
repr = PyString_FromStringAndSize(NULL, 6 * size); |
2265 |
const int expandsize = 6; |
2247 |
#endif |
2266 |
#endif |
|
|
2267 |
|
2268 |
if (size > INT_MAX / expandsize) |
2269 |
return PyErr_NoMemory(); |
2270 |
|
2271 |
repr = PyString_FromStringAndSize(NULL, expandsize * size); |
2248 |
if (repr == NULL) |
2272 |
if (repr == NULL) |
2249 |
return NULL; |
2273 |
return NULL; |
2250 |
if (size == 0) |
2274 |
if (size == 0) |
Lines 4289-4294
PyUnicodeObject *pad(PyUnicodeObject *se
Link Here
|
4289 |
return self; |
4313 |
return self; |
4290 |
} |
4314 |
} |
4291 |
|
4315 |
|
|
|
4316 |
if (left > INT_MAX - self->length || |
4317 |
right > INT_MAX - (left + self->length)) { |
4318 |
PyErr_SetString(PyExc_OverflowError, "padded string is too long"); |
4319 |
return NULL; |
4320 |
} |
4292 |
u = _PyUnicode_New(left + self->length + right); |
4321 |
u = _PyUnicode_New(left + self->length + right); |
4293 |
if (u) { |
4322 |
if (u) { |
4294 |
if (left) |
4323 |
if (left) |