-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-126033: fix a crash in xml.etree.ElementTree.Element.remove
when concurrent mutations happen
#126124
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
bb4f6d2
to
59ade8f
Compare
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.
Is adding version necessary? Would not keeping a strong reference to a child be enough? Look at the list.remove()
code.
Misc/NEWS.d/next/Library/2024-10-29-12-59-45.gh-issue-126033.sM3uCn.rst
Outdated
Show resolved
Hide resolved
Oh yes. I'll try using this one as a basis. |
Ah I know why I couldn't make it work! it's because the children is not a list itself, but just a huge memory area that was dynamically allocated using |
The list storage is also just a huge memory area that was dynamically allocated using At worst, you can get different exceptions (or no exception) in C and Python implementations, but this is fine. |
The difference is that the list object uses |
|
I'm pretty sure I first tried using INCREF/DECREF as usual and encountered an issue with that but I can't remember how. I'll try reproducing this tomorrow. |
@vstinner @serhiy-storchaka friendly ping in case you forgot about this one |
As I wrote, I don't think that 200 lines of tests are needed. I would prefer way less tests. |
I can remove the special test case which makes the test explode as it's only the Python implementation if you want. It would reduce the test by half at least (most of the line length is taken by comments that are needed to explain the discrepency between the Python and the C implementation). |
@vstinner I've removed the pedantic check. However, we still need to have that much of tests because |
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. The C code change LGTM, I didn't review the tests.
Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…en concurrent mutations happen (pythonGH-126124) (cherry picked from commit bab1398) Co-authored-by: Bénédikt Tran <[email protected]>
GH-131929 is a backport of this pull request to the 3.13 branch. |
…en concurrent mutations happen (pythonGH-126124) (cherry picked from commit bab1398) Co-authored-by: Bénédikt Tran <[email protected]>
GH-131930 is a backport of this pull request to the 3.12 branch. |
…en concurrent mutations happen (python#126124)
No need for versioning. Holding a strong reference on the child being compared is enough if we additionally check that the number of children is not changed after the comparison.
The test coverage could be refined but I don't think I need to overcomplicate it even more. I still think we can have a UAF because when one clears the list in
__eq__
but I couldn't find a way to trigger it so I just increfed the item before calling__eq__
. If anyone thinks it's not needed, please tell me why.The patch for
find*
may be more complicated, which is why I splitted the task into three (one for introducing the versioning so that we can work on those failures in parallel).xml.etree.ElementTree.Element.remove
when concurrent mutations happen #126033