Skip to content

Commit

Permalink
Fix crash when accessing nullptr imageRequest
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Jan 14, 2020
1 parent 16ada9d commit cfbd93c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#import "RCTConversions.h"
#import "RCTFabricComponentsPlugins.h"

using namespace facebook::react;

@interface RCTImageComponentView () <RCTImageResponseDelegate>
@end

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

- (void)updateState:(facebook::react::State::Shared const &)state
oldState:(facebook::react::State::Shared const &)oldState
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
{
_state = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(state);
auto _oldState = std::static_pointer_cast<ImageShadowNode::ConcreteState const>(oldState);
Expand Down
8 changes: 8 additions & 0 deletions ReactCommon/fabric/components/image/ImageShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class ImageShadowNode final : public ConcreteViewShadowNode<
*/
void setImageManager(const SharedImageManager &imageManager);

static ImageState initialStateData(
ShadowNodeFragment const &fragment,
SurfaceId const surfaceId,
ComponentDescriptor const &componentDescriptor) {
auto imageSource = ImageSource{ImageSource::Type::Invalid};
return {imageSource, {imageSource, nullptr}};
}

#pragma mark - LayoutableShadowNode

void layout(LayoutContext layoutContext) override;
Expand Down
2 changes: 0 additions & 2 deletions ReactCommon/fabric/components/image/ImageState.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class ImageState final {
imageRequest_(
std::make_shared<ImageRequest>(std::move(imageRequest))){};

ImageState() = default;

/*
* Returns stored ImageSource object.
*/
Expand Down

0 comments on commit cfbd93c

Please sign in to comment.