Skip to content

fix(iOS): Add null check for fontName in RCTGetFontWeight to prevent crash#55414

Open
25harsh wants to merge 1 commit intofacebook:mainfrom
25harsh:fix/ios-null-fontname-crash
Open

fix(iOS): Add null check for fontName in RCTGetFontWeight to prevent crash#55414
25harsh wants to merge 1 commit intofacebook:mainfrom
25harsh:fix/ios-null-fontname-crash

Conversation

@25harsh
Copy link
Contributor

@25harsh 25harsh commented Feb 5, 2026

Summary:

Adds defensive null check for fontName in RCTGetFontWeight before passing it to CFStringFind(), preventing EXC_BAD_ACCESS crash.

Problem

RCTGetFontWeight passes font.fontName directly to CFStringFind() without checking if the result is nil. Unlike Objective-C methods, Core Foundation functions like CFStringFind do not gracefully handle NULL pointers and will
crash with EXC_BAD_ACCESS.

While standard React Native apps typically register fonts at compile time. There are legitimate scenarios where fonts may not be immediately available. eg.
Brownfield applications - runtime font registration using CTFontManagerRegisterGraphicsFont, this causes RN to crash

Changelog:

[IOS][FIXED] - Added null check for fontName in RCTGetFontWeight to prevent crash

Test Plan:

When calling RCTGetFontWeight with nil UIFont (either empty string or unregistered font), no crash observed.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 5, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants