Skip to content

Commit c733980

Browse files
committed
Fix: raise error on neg size in PyBytes_FromStringAndSize
1 parent 217fc3a commit c733980

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

graalpython/com.oracle.graal.python.cext/src/bytesobject.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ Py_ssize_t PyBytes_Size(PyObject *bytes) {
5858
UPCALL_ID(PyBytes_FromStringAndSize);
5959
UPCALL_ID(PyTruffle_Bytes_EmptyWithCapacity);
6060
PyObject* PyBytes_FromStringAndSize(const char* str, Py_ssize_t sz) {
61-
if (str != NULL) {
62-
return ((fromStringAndSize_fun_t)_jls_PyBytes_FromStringAndSize)(polyglot_from_i8_array(str, sz), sz);
63-
}
64-
return UPCALL_CEXT_O(_jls_PyTruffle_Bytes_EmptyWithCapacity, sz);
61+
if (sz < 0) {
62+
PyErr_SetString(PyExc_SystemError, "Negative size passed to PyBytes_FromStringAndSize");
63+
return NULL;
64+
}
65+
if (str != NULL) {
66+
return ((fromStringAndSize_fun_t)_jls_PyBytes_FromStringAndSize)(polyglot_from_i8_array(str, sz), sz);
67+
}
68+
return UPCALL_CEXT_O(_jls_PyTruffle_Bytes_EmptyWithCapacity, sz);
6569
}
6670

6771
PyObject * PyBytes_FromString(const char *str) {

0 commit comments

Comments
 (0)