File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -13347,6 +13347,12 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer)
1334713347PyUnicodeWriter *
1334813348PyUnicodeWriter_Create (Py_ssize_t length )
1334913349{
13350+ if (length < 0 ) {
13351+ PyErr_SetString (PyExc_TypeError ,
13352+ "length must be positive" );
13353+ return NULL ;
13354+ }
13355+
1335013356 const size_t size = sizeof (_PyUnicodeWriter );
1335113357 PyUnicodeWriter * pub_writer = (PyUnicodeWriter * )PyMem_Malloc (size );
1335213358 if (pub_writer == NULL ) {
@@ -13390,6 +13396,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
1339013396 Py_ssize_t newlen ;
1339113397 PyObject * newbuffer ;
1339213398
13399+ assert (length >= 0 );
1339313400 assert (maxchar <= MAX_UNICODE );
1339413401
1339513402 /* ensure that the _PyUnicodeWriter_Prepare macro was used */
@@ -13501,6 +13508,12 @@ _PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer, Py_UCS4 ch)
1350113508int
1350213509PyUnicodeWriter_WriteChar (PyUnicodeWriter * writer , Py_UCS4 ch )
1350313510{
13511+ if (ch > MAX_UNICODE ) {
13512+ PyErr_SetString (PyExc_ValueError ,
13513+ "character must be in range(0x110000)" );
13514+ return -1 ;
13515+ }
13516+
1350413517 return _PyUnicodeWriter_WriteChar ((_PyUnicodeWriter * )writer , ch );
1350513518}
1350613519
You can’t perform that action at this time.
0 commit comments