Skip to content

In backwards compatibility mode, be more permissive of Obj-C nulls #35825

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
Feb 9, 2021

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Feb 8, 2021

The new cast logic checks and aborts if a non-nullable pointer has a null value
at runtime. However, because this was tolerated by the old casting logic, some
apps inadvertently rely on being able to cast such null references.

This change adds specific checks for null pointers in compatibility mode and
handles them similarly to the previous casting logic:

  • Casting to Obj-C or CF type: casting a null pointer succeeds
  • Casting to class-constrained existential: casting a null pointer succeeds
  • Casting to a Swift class type: cast fails without crashing
  • Bridging from Obj-C class to Swift struct type: cast fails without crashing
    This also adds a guard to avoid trying to lookup the dynamic type of a null
    class reference.

In non-compatibility mode, all of the above cause an immediate runtime crash.
The changes here are only intended to support existing binaries running against
new Swift runtimes.

Resolves rdar://72323929

…erences

The new cast logic checks and aborts if a non-nullable pointer has a null value
at runtime.  However, because this was tolerated by the old casting logic, some
apps inadvertently rely on being able to cast such null references.

This change adds specific checks for null pointers in compatibility mode and
handles them similarly to the previous casting logic:
 * Casting to Obj-C or CF type: casting a null pointer succeeds
 * Casting to class-constrained existential: casting a null pointer succeeds
 * Casting to a Swift class type: cast fails without crashing
 * Bridging from Obj-C class to Swift struct type: cast fails without crashing
This also adds a guard to avoid trying to lookup the dynamic type of a null
class reference.

In non-compatibility mode, all of the above cause an immediate runtime crash.
The changes here are only intended to support existing binaries running against
new Swift runtimes.

Resolves rdar://72323929
@tbkka
Copy link
Contributor Author

tbkka commented Feb 8, 2021

@swift-ci Please test

@tbkka tbkka requested a review from mikeash February 8, 2021 19:01
@tbkka
Copy link
Contributor Author

tbkka commented Feb 8, 2021

@swift-ci Please test Windows platform

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

Excellent comments. LGTM.

@tbkka tbkka merged commit f29d049 into swiftlang:main Feb 9, 2021
tbkka added a commit to tbkka/swift that referenced this pull request Feb 9, 2021
…ll references (swiftlang#35825)

(This cherry-picks swiftlang#35825 from main to release/5.4)

The new cast logic checks and aborts if a non-nullable pointer has a null value
at runtime.  However, because this was tolerated by the old casting logic, some
apps inadvertently rely on being able to cast such null references.

This change adds specific checks for null pointers in compatibility mode and
handles them similarly to the previous casting logic:
 * Casting to Obj-C or CF type: casting a null pointer succeeds
 * Casting to class-constrained existential: casting a null pointer succeeds
 * Casting to a Swift class type: cast fails without crashing
 * Bridging from Obj-C class to Swift struct type: cast fails without crashing
This also adds a guard to avoid trying to lookup the dynamic type of a null
class reference.

In non-compatibility mode, all of the above cause an immediate runtime crash.
The changes here are only intended to support existing binaries running against
new Swift runtimes.

Resolves rdar://72323929
tkremenek added a commit that referenced this pull request Feb 9, 2021
…ling54

[5.4] In backwards compatibility mode, be more permissive of Obj-C nulls (#35825)
@tbkka tbkka deleted the tbkka/permissiveObjCNullCastHandling branch August 1, 2024 16:37
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.

2 participants