-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-39421: Fix posible crash in heapq with custom comparison operators #18118
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
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.
import heapq
class h(int):
def __lt__(self, o):
list2.clear()
return NotImplemented
class g(int):
def __lt__(self, o):
list1.clear()
return NotImplemented
list1, list2 = [], []
heapq.heappush(list1, h(0))
heapq.heappush(list2, g(0))
print(list1)
print(list2)
heapq.heappush(list1, g(1))
heapq.heappush(list2, h(1))
print(list1)
print(list2)
This PR does not fix this case. Please take a look
Thanks! I added a test in 9718f66 |
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
Just comment:
In some time, if we can pass objects as a variadic argument.
The code might be cleaner. (I don't deeply think about the possibility)
e.g. Py_INCREF(a, b, c...); Py_DECREF(a, b, c...);
We would need a different function as C does not allow overloads (for |
This should be backported to all branches that are still doing security releases. |
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7, 3.8. |
pythonGH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
pythonGH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
GH-18145 is a backport of this pull request to the 3.7 branch. |
GH-18144 is a backport of this pull request to the 3.8 branch. |
GH-18146 is a backport of this pull request to the 3.6 branch. |
pythonGH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
GH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
GH-18118) (GH-18146) (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
pythonGH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
GH-18149 is a backport of this pull request to the 3.8 branch. |
GH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators (cherry picked from commit 79f89e6) Co-authored-by: Pablo Galindo <[email protected]>
pythonGH-18118) * bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators * fixup! fixup! bpo-39421: Fix posible crash in heapq with custom comparison operators
https://bugs.python.org/issue39421