fix(iOS): Add null check for fontName in RCTGetFontWeight to prevent crash#55414
fix(iOS): Add null check for fontName in RCTGetFontWeight to prevent crash#5541425harsh wants to merge 2 commits into
Conversation
|
@cipolleschi can you please check this |
|
We're hitting this exact crash in production on React Native 0.83.2 with Fabric enabled (iOS). Crash stack from Crashlytics: Happens during concurrent Yoga layout measurement on the Hermes JS thread when a |
|
We're hitting this same crash in production on RN 0.83.2 with Fabric enabled (posted a comment here previously with our Crashlytics stack). One thing worth noting: your PR guards RCTFontWeight RCTGetFontWeight(UIFont *font)
{
if (!font) {
return UIFontWeightRegular;
}
// ... existing code ...
NSString *fontName = font.fontName;
if (fontName) {
// ... suffix matching loop ...
}
auto traits = (__bridge_transfer NSDictionary *)CTFontCopyTraits((CTFontRef)font);
return (RCTFontWeight)[traits[UIFontWeightTrait] doubleValue];
}If |
c1bd1fb to
76e72f6
Compare
|
hey @isaacrowntree thanks for the suggestion. I've gone ahead and added the @cipolleschi would you be able to take a look when you get a chance? Would be great to get this landed given the production crashes folks are seeing. |
b095e09 to
2198915
Compare
Summary:
Adds defensive null check for
fontNameinRCTGetFontWeightbefore passing it toCFStringFind(), preventingEXC_BAD_ACCESScrash.Problem
RCTGetFontWeightpassesfont.fontNamedirectly toCFStringFind()without checking if the result is nil. Unlike Objective-C methods, Core Foundation functions likeCFStringFinddo not gracefully handle NULL pointers and willcrash 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 crashChangelog:
[IOS][FIXED] - Added null check for fontName in RCTGetFontWeight to prevent crash
Test Plan:
When calling
RCTGetFontWeightwith nil UIFont (either empty string or unregistered font), no crash observed.