Skip to content

Commit cfbd93c

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix crash when accessing nullptr imageRequest
Summary: ImageState if created with default constructor is created with `imageRequest_` being nullptr. Calling `getObserverCoordinator()` on it was causing a crash. We create initial state data with `imageRequest` populated. Changelog: [Internal] Reviewed By: shergin Differential Revision: D19332711 fbshipit-source-id: 0266222551dbfb10b3f86e72a43d5306650fd09b
1 parent 16ada9d commit cfbd93c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

React/Fabric/Mounting/ComponentViews/Image/RCTImageComponentView.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#import "RCTConversions.h"
2121
#import "RCTFabricComponentsPlugins.h"
2222

23+
using namespace facebook::react;
24+
2325
@interface RCTImageComponentView () <RCTImageResponseDelegate>
2426
@end
2527

@@ -79,8 +81,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
7981
[super updateProps:props oldProps:oldProps];
8082
}
8183

82-
- (void)updateState:(facebook::react::State::Shared const &)state
83-
oldState:(facebook::react::State::Shared const &)oldState
84+
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
8485
{
8586
_state = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(state);
8687
auto _oldState = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(oldState);

ReactCommon/fabric/components/image/ImageShadowNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class ImageShadowNode final : public ConcreteViewShadowNode<
3535
*/
3636
void setImageManager(const SharedImageManager &imageManager);
3737

38+
static ImageState initialStateData(
39+
ShadowNodeFragment const &fragment,
40+
SurfaceId const surfaceId,
41+
ComponentDescriptor const &componentDescriptor) {
42+
auto imageSource = ImageSource{ImageSource::Type::Invalid};
43+
return {imageSource, {imageSource, nullptr}};
44+
}
45+
3846
#pragma mark - LayoutableShadowNode
3947

4048
void layout(LayoutContext layoutContext) override;

ReactCommon/fabric/components/image/ImageState.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class ImageState final {
2424
imageRequest_(
2525
std::make_shared<ImageRequest>(std::move(imageRequest))){};
2626

27-
ImageState() = default;
28-
2927
/*
3028
* Returns stored ImageSource object.
3129
*/

0 commit comments

Comments
 (0)