Double-inheriting from two buffer classes can cause corruption #104297
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-bug
An unexpected behavior, bug, or error
If you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements
bf_getbuffer
and the second also implementsbf_releasebuffer
, then if you create a memoryview from the child class, on release the second class'sbf_releasebuffer
will be called, which may break that class's invariants.Demonstration:
This is unlikely to happen in practice because in practice any useful C buffer class will have to store some data in its C struct, so it won't be possible to double-inherit from it and another buffer, but still we should ideally protect against it.
I found out about this case while playing with PEP-688 edge cases in #104227, but the reproduction case does not rely on PEP 688 changes, and it should reproduce also on earlier Python versions. (The exact assertion failure won't, because I added that assertion in #104227; previously, you'd just set the bytearray's ob_exports field to -1 and havoc would ensue.)
The text was updated successfully, but these errors were encountered: