Skip to content

[Runtime] Fix crash in protocol conformance checks on KVO artificial subclasses. #37973

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

Merged
merged 1 commit into from
Jun 23, 2021

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Jun 17, 2021

tryGetCompleteMetadataNonblocking crashes on artificial subclasses due to the NULL type descriptor. Explicitly check for artificial subclasses in getSuperclassForMaybeIncompleteMetadata and immediately return their Superclass field. Artificial subclasses are always fully initialized so we don't need to do anything special for them.

rdar://72583931

…subclasses.

tryGetCompleteMetadataNonblocking crashes on artificial subclasses due to the NULL type descriptor. Explicitly check for artificial subclasses in getSuperclassForMaybeIncompleteMetadata and immediately return their Superclass field. Artificial subclasses are always fully initialized so we don't need to do anything special for them.

rdar://72583931
@mikeash mikeash requested review from DougGregor and tbkka June 17, 2021 18:50
// tryGetCompleteMetadataNonblocking will crash on them. However, they're
// always fully set up, so we can just skip it and fetch the Subclass field.
if (classMetadata->isTypeMetadata() && classMetadata->isArtificialSubclass())
return {classMetadata->Superclass, MetadataState::Complete};
Copy link
Contributor

@jckarter jckarter Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places, we do this check for artificial subclasses in a loop, crawling up the superclass tree until we find a real class. I don't know if that's just paranoia, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can happen at least in theory. No idea if it happens in reality, but it's good to handle. In this particular case, the loop is exterior to this function, as other code uses this function to walk the entire superclass chain. Returning artificial subclasses in that loop is unnecessary but harmless.

@mikeash
Copy link
Contributor Author

mikeash commented Jun 17, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c3aa443

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good then. Thanks Mike!

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c3aa443

@mikeash
Copy link
Contributor Author

mikeash commented Jun 22, 2021

@swift-ci please test macOS platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c3aa443

@mikeash
Copy link
Contributor Author

mikeash commented Jun 22, 2021

@swift-ci please test macos platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c3aa443

@mikeash
Copy link
Contributor Author

mikeash commented Jun 22, 2021

@swift-ci please smoke test macOS platform

@mikeash mikeash merged commit 53fe241 into swiftlang:main Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants