From cfed46e00a00380f05917c533a259fe45697a5ec Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Nov 2011 01:29:14 +0100 Subject: [PATCH] PyUnicode_FromKindAndData() fails with a ValueError if size < 0 --- Objects/unicodeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 30a1377add9..7f079e78997 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; }