File tree 1 file changed +13
-0
lines changed
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)
13347
13347
PyUnicodeWriter *
13348
13348
PyUnicodeWriter_Create (Py_ssize_t length )
13349
13349
{
13350
+ if (length < 0 ) {
13351
+ PyErr_SetString (PyExc_TypeError ,
13352
+ "length must be positive" );
13353
+ return NULL ;
13354
+ }
13355
+
13350
13356
const size_t size = sizeof (_PyUnicodeWriter );
13351
13357
PyUnicodeWriter * pub_writer = (PyUnicodeWriter * )PyMem_Malloc (size );
13352
13358
if (pub_writer == NULL ) {
@@ -13390,6 +13396,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
13390
13396
Py_ssize_t newlen ;
13391
13397
PyObject * newbuffer ;
13392
13398
13399
+ assert (length >= 0 );
13393
13400
assert (maxchar <= MAX_UNICODE );
13394
13401
13395
13402
/* ensure that the _PyUnicodeWriter_Prepare macro was used */
@@ -13501,6 +13508,12 @@ _PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer, Py_UCS4 ch)
13501
13508
int
13502
13509
PyUnicodeWriter_WriteChar (PyUnicodeWriter * writer , Py_UCS4 ch )
13503
13510
{
13511
+ if (ch > MAX_UNICODE ) {
13512
+ PyErr_SetString (PyExc_ValueError ,
13513
+ "character must be in range(0x110000)" );
13514
+ return -1 ;
13515
+ }
13516
+
13504
13517
return _PyUnicodeWriter_WriteChar ((_PyUnicodeWriter * )writer , ch );
13505
13518
}
13506
13519
You can’t perform that action at this time.
0 commit comments