Skip to content

Commit 5ecaba8

Browse files
ryanfrawleyRyan Frawley
andauthored
fix: ios breaking changes for RCTImage use-after-free crash (#2850)
# Summary Adopts the [breaking change bug fix](facebook/react-native@3b46755) in React Native RCTImage for iOS to fix a rare use-after-free race condition in the image progress observer. (See React Native PR for more details) ## Test Plan Rerun nightly test suite and verify no more breakages. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | n/a | | Android | n/a | | Web | n/a | ## Checklist - [x] I have tested this on a device and a simulator - [ ] I added documentation in `README.md` - [ ] I updated the typed files (typescript) - [ ] I added a test for the API in the `__tests__` folder Co-authored-by: Ryan Frawley <ryguy@meta.com>
1 parent 0f94a94 commit 5ecaba8

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

apple/Elements/RNSVGImage.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#import "RNSVGViewBox.h"
2828

2929
#ifdef RCT_NEW_ARCH_ENABLED
30+
#import <memory>
31+
3032
#import <React/RCTConversions.h>
3133
#import <React/RCTFabricComponentsPlugins.h>
3234
#import <React/RCTImageResponseObserverProxy.h>
@@ -45,7 +47,7 @@ @implementation RNSVGImage {
4547

4648
#ifdef RCT_NEW_ARCH_ENABLED
4749
RNSVGImageShadowNode::ConcreteState::Shared _state;
48-
RCTImageResponseObserverProxy _imageResponseObserverProxy;
50+
std::shared_ptr<RCTImageResponseObserverProxy> _imageResponseObserverProxy;
4951
#endif // RCT_NEW_ARCH_ENABLED
5052
}
5153
#ifdef RCT_NEW_ARCH_ENABLED
@@ -62,7 +64,7 @@ - (instancetype)initWithFrame:(CGRect)frame
6264
static const auto defaultProps = std::make_shared<const RNSVGImageProps>();
6365
_props = defaultProps;
6466

65-
_imageResponseObserverProxy = RCTImageResponseObserverProxy(self);
67+
_imageResponseObserverProxy = std::make_shared<RCTImageResponseObserverProxy>(self);
6668
}
6769
return self;
6870
}
@@ -99,6 +101,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
99101

100102
setCommonRenderableProps(newProps, self);
101103
_props = std::static_pointer_cast<RNSVGImageProps const>(props);
104+
105+
[super updateProps:props oldProps:oldProps];
102106
}
103107

104108
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
@@ -118,14 +122,14 @@ - (void)_setStateAndResubscribeImageResponseObserver:(RNSVGImageShadowNode::Conc
118122
{
119123
if (_state) {
120124
auto &observerCoordinator = _state->getData().getImageRequest().getObserverCoordinator();
121-
observerCoordinator.removeObserver(_imageResponseObserverProxy);
125+
observerCoordinator.removeObserver(*_imageResponseObserverProxy);
122126
}
123127

124128
_state = state;
125129

126130
if (_state) {
127131
auto &observerCoordinator = _state->getData().getImageRequest().getObserverCoordinator();
128-
observerCoordinator.addObserver(_imageResponseObserverProxy);
132+
observerCoordinator.addObserver(*_imageResponseObserverProxy);
129133
}
130134
}
131135

0 commit comments

Comments
 (0)