mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	PyUnicode_FromKindAndData() fails with a ValueError if size < 0
This commit is contained in:
		
							parent
							
								
									42885206ec
								
							
						
					
					
						commit
						cfed46e00a
					
				
					 1 changed files with 4 additions and 1 deletions
				
			
		| 
						 | 
					@ -1906,6 +1906,10 @@ _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size)
 | 
				
			||||||
PyObject*
 | 
					PyObject*
 | 
				
			||||||
PyUnicode_FromKindAndData(int kind, const void *buffer, Py_ssize_t size)
 | 
					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) {
 | 
					    switch(kind) {
 | 
				
			||||||
    case PyUnicode_1BYTE_KIND:
 | 
					    case PyUnicode_1BYTE_KIND:
 | 
				
			||||||
        return _PyUnicode_FromUCS1(buffer, size);
 | 
					        return _PyUnicode_FromUCS1(buffer, size);
 | 
				
			||||||
| 
						 | 
					@ -1914,7 +1918,6 @@ PyUnicode_FromKindAndData(int kind, const void *buffer, Py_ssize_t size)
 | 
				
			||||||
    case PyUnicode_4BYTE_KIND:
 | 
					    case PyUnicode_4BYTE_KIND:
 | 
				
			||||||
        return _PyUnicode_FromUCS4(buffer, size);
 | 
					        return _PyUnicode_FromUCS4(buffer, size);
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        assert(0 && "invalid kind");
 | 
					 | 
				
			||||||
        PyErr_SetString(PyExc_SystemError, "invalid kind");
 | 
					        PyErr_SetString(PyExc_SystemError, "invalid kind");
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue