mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	PyUnicode_Substring() now accepts end bigger than string length
Fix also a bug: call PyUnicode_READY() before reading string length.
This commit is contained in:
		
							parent
							
								
									9f789e7f63
								
							
						
					
					
						commit
						de636f3c34
					
				
					 1 changed files with 6 additions and 3 deletions
				
			
		| 
						 | 
					@ -10447,6 +10447,11 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 | 
				
			||||||
    int kind;
 | 
					    int kind;
 | 
				
			||||||
    Py_ssize_t length;
 | 
					    Py_ssize_t length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (PyUnicode_READY(self) == -1)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    end = Py_MIN(end, PyUnicode_GET_LENGTH(self));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (start == 0 && end == PyUnicode_GET_LENGTH(self))
 | 
					    if (start == 0 && end == PyUnicode_GET_LENGTH(self))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (PyUnicode_CheckExact(self)) {
 | 
					        if (PyUnicode_CheckExact(self)) {
 | 
				
			||||||
| 
						 | 
					@ -10461,13 +10466,11 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end)
 | 
				
			||||||
    if (length == 1)
 | 
					    if (length == 1)
 | 
				
			||||||
        return unicode_getitem((PyUnicodeObject*)self, start);
 | 
					        return unicode_getitem((PyUnicodeObject*)self, start);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (start < 0 || end < 0 || end > PyUnicode_GET_LENGTH(self)) {
 | 
					    if (start < 0 || end < 0) {
 | 
				
			||||||
        PyErr_SetString(PyExc_IndexError, "string index out of range");
 | 
					        PyErr_SetString(PyExc_IndexError, "string index out of range");
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (PyUnicode_READY(self) == -1)
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    kind = PyUnicode_KIND(self);
 | 
					    kind = PyUnicode_KIND(self);
 | 
				
			||||||
    data = PyUnicode_1BYTE_DATA(self);
 | 
					    data = PyUnicode_1BYTE_DATA(self);
 | 
				
			||||||
    return PyUnicode_FromKindAndData(kind,
 | 
					    return PyUnicode_FromKindAndData(kind,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue