Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jamesderlin
Copy link
Contributor

iOS developers can accidentally pass an NSData object directly to
FlutterStandardCodec and forget to wrap it in
FlutterStandardTypedData. This failure won't be caught until
runtime.

Let's make FlutterStandardCodec more tolerant by making it assume
that NSData should be treated as a binary blob and by wrapping it
automatically.

Fixes flutter/flutter#17449

Testing Done:

  • Made a sample Flutter iOS application that created a
    FlutterMethodChannel and invoked a method using an NSData*
    argument. Verified that the Flutter method handler received the
    message and that the MethodCall.arguments was a UInt8Array that
    preserved the original byte order.
  • Verified that without this change, the same sample application
    crashed when run in debug mode.

iOS developers can accidentally pass an `NSData` object directly to
`FlutterStandardCodec` and forget to wrap it in
`FlutterStandardTypedData`.  This failure won't be caught until
runtime.

Let's make `FlutterStandardCodec` more tolerant by making it assume
that `NSData` should be treated as a binary blob and by wrapping it
automatically.

Fixes flutter/flutter#17449

Testing Done:
* Made a sample Flutter iOS application that created a
  `FlutterMethodChannel` and invoked a method using an `NSData*`
  argument.  Verified that the Flutter method handler received the
  message and that the `MethodCall.arguments` was a `UInt8Array` that
  preserved the original byte order.
* Verified that without this change, the same sample application
  crashed when run in debug mode.
@alanrussian
Copy link
Contributor

Should this documentation be updated (https://flutter.io/platform-channels)? If NSData is the preferred type to use in Objective-C, should it mention NSData instead of FlutterStandardTypedData typedDataWithBytes:?

cc @johnfesa who's more familiar with Objective-C and recommended filing the issue I filed.

@jamesderlin
Copy link
Contributor Author

Should this documentation be updated (https://flutter.io/platform-channels)?

I lean toward no. This change adds a convenience to tolerate passing NSData directly. However, this convenience is asymmetric; the encoded stream of bytes will continue to be decoded as FlutterStandardTypedData.

Copy link
Contributor

@alanrussian alanrussian left a comment

Choose a reason for hiding this comment

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

LGTM but please get approval from someone with more Objective-C familiarity (I have very little). Thanks!

@jamesderlin jamesderlin requested review from chinmaygarde and removed request for cbracken September 12, 2018 00:11
@chinmaygarde
Copy link
Contributor

Sorry about the late reply. Can this be committed?

@jamesderlin jamesderlin merged commit 5b8e8c3 into flutter:master Sep 21, 2018
@jamesderlin jamesderlin deleted the jamesderlin/codec-nsdata branch September 21, 2018 22:46
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 21, 2018
flutter/engine@a8890fd...5b8e8c3

git log a8890fd..5b8e8c3 --no-merges --oneline
5b8e8c3 Make FlutterStandardCodec handle writing NSData (flutter/engine#6207)
02901b7 Decouple PlatformViewsController from FlutterView. (flutter/engine#6303)
cc3009c Revert 'Dart SDK roll for 2018/09/20' 8471862 (flutter/engine#6309)
bbdf7c1 Revert "Fix a compilation problem when using iPhoneOS12.0sdk(Xcode10) && clang version 7.0.0." (flutter/engine#6307)
dea0921 Roll src/third_party/skia c25f440d537e..358558a4cecc (17 commits) (flutter/engine#6308)
d29c7db Add logging if FlutterDartProject fails to load the application kernel snapshot (flutter/engine#6257)
2a1debf Update deprecated subtags from language subtag registry. (flutter/engine#6280)
540cd96 Add Xib splashscreen support (flutter/engine#6289)
05f21e6 Fix a compilation problem when using iPhoneOS12.0sdk(Xcode10) && clang version 7.0.0. (flutter/engine#6279)
ca6f103 Roll src/third_party/skia d842557c0724..c25f440d537e (10 commits) (flutter/engine#6304)
3b46705 Roll src/third_party/skia 38ca6d509d9f..d842557c0724 (5 commits) (flutter/engine#6302)
0c166fe Roll src/third_party/skia 05cf051f0252..38ca6d509d9f (1 commits) (flutter/engine#6301)
cf0fbad Roll src/third_party/skia 44c6167c4125..05cf051f0252 (4 commits) (flutter/engine#6299)
2ec20aa Remove bottom safe-area padding when keyboard up (flutter/engine#6297)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2018
flutter/engine@cc3009c...7648d21

git log cc3009c..7648d21 --no-merges --oneline
7648d21 Dart SDK roll for 2018-09-21 (flutter/engine#6311)
5b8e8c3 Make FlutterStandardCodec handle writing NSData (flutter/engine#6207)
02901b7 Decouple PlatformViewsController from FlutterView. (flutter/engine#6303)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2018
flutter/engine@cc3009c...19ac3e1

git log cc3009c..19ac3e1 --no-merges --oneline
19ac3e1 Roll src/third_party/skia 358558a4cecc..11f4994b84e1 (2 commits) (flutter/engine#6312)
7648d21 Dart SDK roll for 2018-09-21 (flutter/engine#6311)
5b8e8c3 Make FlutterStandardCodec handle writing NSData (flutter/engine#6207)
02901b7 Decouple PlatformViewsController from FlutterView. (flutter/engine#6303)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 22, 2018
flutter/engine@cc3009c...f3a3d0c

git log cc3009c..f3a3d0c --no-merges --oneline
f3a3d0c Roll src/third_party/skia 11f4994b84e1..175b587a634d (1 commits) (flutter/engine#6313)
19ac3e1 Roll src/third_party/skia 358558a4cecc..11f4994b84e1 (2 commits) (flutter/engine#6312)
7648d21 Dart SDK roll for 2018-09-21 (flutter/engine#6311)
5b8e8c3 Make FlutterStandardCodec handle writing NSData (flutter/engine#6207)
02901b7 Decouple PlatformViewsController from FlutterView. (flutter/engine#6303)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 22, 2018
flutter/engine@cc3009c...f3a3d0c

git log cc3009c..f3a3d0c --no-merges --oneline
f3a3d0c Roll src/third_party/skia 11f4994b84e1..175b587a634d (1 commits) (flutter/engine#6313)
19ac3e1 Roll src/third_party/skia 358558a4cecc..11f4994b84e1 (2 commits) (flutter/engine#6312)
7648d21 Dart SDK roll for 2018-09-21 (flutter/engine#6311)
5b8e8c3 Make FlutterStandardCodec handle writing NSData (flutter/engine#6207)
02901b7 Decouple PlatformViewsController from FlutterView. (flutter/engine#6303)


The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants