-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-31455: avoid calling "PyObject_GetAttrString()" with a live exception set #3545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ser code) with a live exception set.
Please open an issue on the bug tracker. This isn't a trivial change. I think that it would be better to silence only |
Found as part of #3279, which started showing side-effects due to this bug. |
…ser() and propagate all other exceptions.
PR updated, test and News entry added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I left just few nitpicks.
Lib/test/test_xml_etree.py
Outdated
|
||
ET.XMLParser(target=RaisingBuilder(what=AttributeError)) | ||
for event in ('start', 'data', 'end', 'comment', 'pi'): | ||
ET.XMLParser(target=RaisingBuilder(event, what=AttributeError)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close the parser explicitly. Just for the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (Requires parsing something, though.)
Lib/test/test_xml_etree.py
Outdated
@@ -2400,6 +2400,29 @@ def _check_sample1_element(self, e): | |||
self.assertEqual(child.tail, 'tail') | |||
self.assertEqual(child.attrib, {}) | |||
|
|||
def test_exceptions(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't XMLParserTest
be better place? In any case I think it is better to place this method at the end of the class, after testing normal cases.
And maybe use more specific method name? "test_builder_attribute_errors" or something like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I kept it in the test class because the exceptions are related to the behaviour of the TreeBuilder
.
Modules/_elementtree.c
Outdated
@@ -3259,6 +3259,17 @@ xmlparser_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
return (PyObject *)self; | |||
} | |||
|
|||
static int | |||
ignore_attribute_error(PyObject *value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this {
on new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Modules/_elementtree.c
Outdated
@@ -3313,14 +3324,26 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *html, | |||
self->target = target; | |||
|
|||
self->handle_start = PyObject_GetAttrString(target, "start"); | |||
if (ignore_attribute_error(self->handle_start)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New PEP 7 rules require braces even around simple if
body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (Sad in this case, given the relation between "active" code and error handling code.)
…isbehaviour, not basic behaviour.
PR updated. |
Thanks @scoder for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
Sorry, @scoder and @serhiy-storchaka, I could not cleanly backport this to |
…pythonGH-3545) * Avoid calling "PyObject_GetAttrString()" (and potentially executing user code) with a live exception set. * Ignore only AttributeError on attribute lookups in ElementTree.XMLParser() and propagate all other exceptions. (cherry picked from commit c8d8e15)
GH-3585 is a backport of this pull request to the 3.6 branch. |
Thanks @scoder for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7. |
Sorry, @scoder and @serhiy-storchaka, I could not cleanly backport this to |
https://bugs.python.org/issue31455