Skip to content

fix(UBSAN): ensure [RCTUITextField validAttributesForMarkedText] Is non null #2515

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 18, 2025

Conversation

Saadnajmi
Copy link
Collaborator

Summary:

Internally, we build with UndefinedBehaviorSanitizer, which caught an instance of a method returning nil while marked as non null. Apple documentation says that method should return an empty array as a fallback, so let's do that.

Test Plan:

Tested internally.

@Saadnajmi Saadnajmi requested a review from Copilot June 18, 2025 19:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue where the method [RCTUITextField validAttributesForMarkedText] was returning nil, which violates Apple's documentation and triggers UBSAN warnings. The change ensures the method returns an empty array as a fallback instead of nil.

  • Updated the return value of validAttributesForMarkedText to use a nil coalescing fallback (@[]).
Comments suppressed due to low confidence (1)

packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm:164

  • The nil coalescing operator ensures a non-null return value, which is required by the API contract. Please verify that self.currentEditor always returns an object of type NSTextView to avoid potential issues with unsafe type casting.
	return ((NSTextView *)self.currentEditor).validAttributesForMarkedText ?: @[];

@Saadnajmi
Copy link
Collaborator Author

@copilot Could you backport this PR to the following branches?

  • 0.78-stable
  • 0.77-stable
  • 0.76-stable
  • 0.75-stable
  • 0.74-stable

@Saadnajmi Saadnajmi merged commit 1b7efce into microsoft:main Jun 18, 2025
12 checks passed
@Saadnajmi Saadnajmi deleted the ubsan branch June 18, 2025 22:03
Saadnajmi added a commit that referenced this pull request Jul 1, 2025
Saadnajmi added a commit that referenced this pull request Jul 1, 2025
Saadnajmi added a commit that referenced this pull request Jul 1, 2025
Saadnajmi added a commit that referenced this pull request Jul 1, 2025
Saadnajmi added a commit that referenced this pull request Jul 1, 2025
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