Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash when insert nil value into a dictionary #30066

Conversation

marksinkovics
Copy link
Contributor

Summary

This PR attempts to fix issue #28278 and #29525

On Crashlytics, the following error occurs in file RCTWebSocketModule.m at method -[RCTWebSocketModule webSocket:didFailWithError:] when a nil value is inserted into a dictionary as a value.

Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail:

  • it converts error to empty NSString if the original value is nil
  • it converts socketID to a NSNumber object, which stores -1 if the original value is nil

Changelog

[iOS] [Fixed] - A crash in WebSocket module

Test Plan

We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

- Convert `error` to empty NSString if the original value is nil
- Convert `socketID` to a NSNumber object, which stores -1 if the original value is nil
@facebook-github-bot facebook-github-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 Sep 29, 2020
@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels Sep 29, 2020
@analysis-bot
Copy link

analysis-bot commented Sep 29, 2020

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: d8b0e9d

@analysis-bot
Copy link

analysis-bot commented Sep 29, 2020

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,389,897 0
android hermes armeabi-v7a 7,017,213 0
android hermes x86 7,832,109 0
android hermes x86_64 7,721,595 0
android jsc arm64-v8a 9,536,198 0
android jsc armeabi-v7a 9,151,226 0
android jsc x86 9,400,874 0
android jsc x86_64 9,982,584 0

Base commit: d8b0e9d

@@ -168,7 +168,11 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketFailed" body:@{@"message" : error.localizedDescription, @"id" : socketID}];
NSDictionary *body = @{
@"message" : error.localizedDescription ?: @"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say something like "undefined" instead of empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment. I updated the error message to Undefined, error is nil.
Please let me know if you have any further feedback.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sammy-SC has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@sammy-SC
Copy link
Contributor

thank you @marksinkovics

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @marksinkovics in 748aa13.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 12, 2020
kelset pushed a commit that referenced this pull request Nov 27, 2020
Summary:
This PR attempts to fix issue #28278 and #29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: #30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
brentvatne pushed a commit to expo/react-native that referenced this pull request Dec 3, 2020
Summary:
This PR attempts to fix issue facebook#28278 and facebook#29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: facebook#28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: facebook#30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants