bpo-46048: Fix parsing of single character lines in getpath readlines() (GH-30048)

This commit is contained in:
Steve Dower 2021-12-11 13:43:40 +00:00 committed by GitHub
parent 4fe5585240
commit 971ece8e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View file

@ -386,11 +386,11 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
wchar_t *p1 = wbuffer;
wchar_t *p2 = p1;
while ((p2 = wcschr(p1, L'\n')) != NULL) {
size_t cb = p2 - p1;
while (cb && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
Py_ssize_t cb = p2 - p1;
while (cb >= 0 && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
--cb;
}
PyObject *u = PyUnicode_FromWideChar(p1, cb ? cb + 1 : 0);
PyObject *u = PyUnicode_FromWideChar(p1, cb >= 0 ? cb + 1 : 0);
if (!u || PyList_Append(r, u) < 0) {
Py_XDECREF(u);
Py_CLEAR(r);