summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:29:14 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:29:14 (GMT)
commitcfed46e00a00380f05917c533a259fe45697a5ec (patch)
tree6a640ef4409ec5d81c8c453e7b9802156fadc639
parent42885206ece169e148314def9ade7054675a068c (diff)
downloadcpython-cfed46e00a00380f05917c533a259fe45697a5ec.zip
cpython-cfed46e00a00380f05917c533a259fe45697a5ec.tar.gz
cpython-cfed46e00a00380f05917c533a259fe45697a5ec.tar.bz2
PyUnicode_FromKindAndData() fails with a ValueError if size < 0
-rw-r--r--Objects/unicodeobject.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 30a1377..7f079e7 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1906,6 +1906,10 @@ _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size)
PyObject*
PyUnicode_FromKindAndData(int kind, const void *buffer, Py_ssize_t size)
{
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "size must be positive");
+ return NULL;
+ }
switch(kind) {
case PyUnicode_1BYTE_KIND:
return _PyUnicode_FromUCS1(buffer, size);
@@ -1914,7 +1918,6 @@ PyUnicode_FromKindAndData(int kind, const void *buffer, Py_ssize_t size)
case PyUnicode_4BYTE_KIND:
return _PyUnicode_FromUCS4(buffer, size);
default:
- assert(0 && "invalid kind");
PyErr_SetString(PyExc_SystemError, "invalid kind");
return NULL;
}