Skip to content

bpo-44232: Fix type_new crash caused by AssertionError#26358

Closed
Fidget-Spinner wants to merge 1 commit into
python:mainfrom
Fidget-Spinner:typeobject_new_type_crash
Closed

bpo-44232: Fix type_new crash caused by AssertionError#26358
Fidget-Spinner wants to merge 1 commit into
python:mainfrom
Fidget-Spinner:typeobject_new_type_crash

Conversation

@Fidget-Spinner

@Fidget-Spinner Fidget-Spinner commented May 25, 2021

Copy link
Copy Markdown
Member

type can sometimes be NULL due to invalid tp_new of base classes, so just return NULL in those cases (the old code prior to refactoring in ecf14e6 did this).

This only affects debug builds.

https://bugs.python.org/issue44232

@vstinner

Copy link
Copy Markdown
Member

I proposed a different fix in PR #PR 26359. I didn't notice that you was working on a fix in parallel :-)

@sweeneyde

Copy link
Copy Markdown
Member

Why not keep the assertion but add a null check for the return value of winner->tp_new and return -1 from type_new_get_bases?

Then you keep the invariant of "-1 means error, 0 means didn't assign to *type, 1 means assigned to *type"

@Fidget-Spinner

Copy link
Copy Markdown
Member Author

I proposed a different fix in PR #PR 26359. I didn't notice that you was working on a fix in parallel :-)

No worries. This is funny and slightly sad at the same time but I'm glad either way some kind of fix is going in.

@Fidget-Spinner

Fidget-Spinner commented May 25, 2021

Copy link
Copy Markdown
Member Author

Why not keep the assertion but add a null check for the return value of winner->tp_new and return -1 from type_new_get_bases?

Then you keep the invariant of "-1 means error, 0 means didn't assign to *type, 1 means assigned to *type"

Oops our messages were posted at the same time and I missed yours. Sorry.

@sweeneyde I considered that. But I chose to delete the assertion because that's the old behavior before the refactor (which caused this regression), and I didn't want to take any chances: ecf14e6#diff-1decebeef15f4e0b0ce106c665751ec55068d4d1d1825847925ad4f528b5b872L2464
I felt it was safer to restore the old behavior.

Anyways, Victor's GH-26359 does what you're suggesting. So you can consider his PR instead.

@pablogsal

Copy link
Copy Markdown
Member

Victor's PR has been merged, so I'm closing this

@pablogsal pablogsal closed this May 25, 2021
@Fidget-Spinner
Fidget-Spinner deleted the typeobject_new_type_crash branch May 26, 2021 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants