Skip to content

[release/7.0] [metadata] Skip null vtable entries when checking covariant return overrides #76324

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 4 commits into from
Sep 29, 2022

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 28, 2022

Backport of #76323 to release/7.0

/cc @lambdageek

Customer Impact

Customers using code that uses C# covariant returns in mobile or WebAssembly applications experienced crashes when using classes that re-abstracted virtual methods that had covariant returns in child subclasses. At least one commercial NuGet package used this pattern which prevented their customers from deploying the library in Android applications.

See dotnet/maui#6811

Testing

New CI test and manual testing

Risk

Low. The change affects validation done by the runtime while loading classes. A null pointer dereference is avoided. No existing checks are removed, no new checks are added. Code generation is unchanged. Any code that previously worked will continue to work.

When there are covariant return overrides, we check the vtable slot in every
parent class for signature compatability with the proposed override.

However if one of the ancestor classes is abstract, it could have an
abstract override for hte method:

    class Base {
      public virtual Base Method() => this;
    }
    public abstract Intermediate : Base {
      public override abstract Base Method();
    }
    public Leaf : Intermediate {
      public override Leaf Method() => this;
    }

In this case when we're checking that Leaf.Method is compatible with
the vtable slot in Intermediate, we will see a null method (since
Intermediate is abstract).  In such cases we can skip over the class
and continue with its parent.

Fixes
#76312
@ghost ghost added the area-VM-meta-mono label Sep 28, 2022
@lambdageek lambdageek added the Servicing-consider Issue for next servicing release review label Sep 28, 2022
@lambdageek lambdageek added this to the 7.0.0 milestone Sep 28, 2022
@carlossanlop
Copy link
Contributor

@lambdageek if this is ready, can you please send an email to Tactics requesting approval?

@lewing lewing added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 29, 2022
@lewing
Copy link
Member

lewing commented Sep 29, 2022

approved in email

@carlossanlop
Copy link
Contributor

Approved by Tactics, signed off, green CI. This is fully baked. :shipit:

@carlossanlop carlossanlop merged commit b099c69 into release/7.0 Sep 29, 2022
@carlossanlop carlossanlop deleted the backport/pr-76323-to-release/7.0 branch September 29, 2022 21:52
@ghost ghost locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-meta-mono Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants