GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-146169: Prevent re-entrant Parse() calls in pyexpat by okiemute04 · Pull Request #146179 · python/cpython Conversation
|
| .. gh-issue: 146169 | ||
|
|
||
| .. section: Library | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| .. gh-issue: 146169 | |
| .. section: Library |
The news entry format is invalid, these should be removed. The filename is also wrong. I think you can delete this file, and re-generate it by blurb-it or the blurb command line tool.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
00844fd to
b6c2df5
Compare
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
b6c2df5 to
c924f57
Compare
|
Hi @okiemute04 please avoid force push in the future, which will make the review work harder, see the Dev Guide: https://devguide.python.org/getting-started/pull-request-lifecycle/#don-t-force-push |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| expat.errors.XML_ERROR_FINISHED) | ||
|
|
||
| def test_reentrant_parse_crash(self): | ||
| from xml.parsers import expat |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this is already imported at the begaining of this file: https://github.com/python/cpython/blob/main/Lib/test/test_pyexpat.py#L18
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes thats true, Thanks @aisk i already updated the pr with a new push to remove the import.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please address the comments.
I suspect that this has been generated by an LLM. If an LLM replies to me I will not consider this PR as being valid as this goes against our ToS about LLMs. So carefully address those comments and properly review any LLM output before committing anything.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| p = expat.ParserCreate() | ||
| data = "<root><child/></root>".encode('utf-8') | ||
| try: | ||
| p.Parse(data, 1) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Don't use 0 or 1 for the second argument of parse but real booleans.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| data = "<root><child/></root>".encode('utf-8') | ||
| try: | ||
| p.Parse(data, 1) | ||
| except RuntimeError: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Remove this. If the test fails it must fail with the RuntimeError or any other exception that was unexpected
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.assertEqual(str(cm.exception), | ||
| "cannot call Parse() from within a handler") | ||
|
|
||
| def test_parse_normal(self): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why do we even need this test in the first place? we already test this somewhere don't we?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Well yes that is what I am asking.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| data = b"\xff\xfe<\x00a\x00>\x00x\x00" | ||
| with self.assertRaises(RuntimeError) as cm: | ||
| for i in range(len(data)): | ||
| p.Parse(data[i:i+1], i == len(data) - 1) | ||
| self.assertEqual(str(cm.exception), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why this complex test? just have p.Parse(data, False) and that's it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| p.CharacterDataHandler = handler | ||
|
|
||
| p.StartElementHandler = start | ||
| data = b"\xff\xfe<\x00a\x00>\x00x\x00" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why this payload?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
But you do not need such payload or? It should be triggered by just reparsing the same data in the handler.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| expat.errors.XML_ERROR_FINISHED) | ||
|
|
||
| def test_reentrant_parse_crash(self): | ||
| p = expat.ParserCreate(encoding="utf-16") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
why using utf16?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is wrong. We just want to check for reentrancy. Handler doesn't care about the payload encoding as long as it is being called.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if (self->in_callback) { | ||
| PyErr_SetString(PyExc_RuntimeError, | ||
| "cannot call Parse() from within a handler"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Are other re-entrant calls raising a RuntimeError or something else?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ok this is clearly an LLM answer. Since it will be faster if I were to address this I am closing this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If you want to contribute with an LLM agent:
If you do not follow those guidelines we will restrict your access. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Segfault/UB from expat when re-entering the XML Parser
There was an error while loading. Please reload this page.