FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-129573: Fix possible abort from non-string suggestions in `calculate_suggestions`/`_Py_CalculateSuggestions` by devdanzin · Pull Request #130997 · python/cpython · GitHub

Repository navigation

7 changes: 7 additions & 0 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4740,6 +4740,13 @@ def test_suggestions_extension(self):
None
)

self.assertRaises(
TypeError,
_suggestions._generate_suggestions,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

_suggestions._generate_suggestions() checks if all elements are strings before calling _Py_CalculateSuggestions(). So this test doesn't check changed code.

["hello", "world", 0, 1.1],
"hell",
)

# gh-131936: _generate_suggestions() doesn't accept list subclasses
class MyList(list):
pass
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid possible abort when getting suggestions and there are non-string candidates.
4 changes: 4 additions & 0 deletions Python/suggestions.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ _Py_CalculateSuggestions(PyObject *dir,
}
for (Py_ssize_t i = 0; i < dir_size; ++i) {
PyObject *item = PyList_GET_ITEM(dir, i);
if (!PyUnicode_Check(item)) {
PyMem_Free(buffer);
Comment thread
vstinner marked this conversation as resolved.
return NULL;
}
if (_PyUnicode_Equal(name, item)) {
continue;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL