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

Added exception if you try to reply with a non-direct ByteBuffer. #25952

Merged
merged 4 commits into from
May 12, 2021

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented May 5, 2021

issue: flutter/flutter#81875

I couldn't find an appropriate place to update the documentation so I decided for an exception. People can run into this problem if they incorrectly implement a channel with a binarycodec.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

ensureRunningOnMainThread();
if (!message.isDirect()) {
Copy link

Choose a reason for hiding this comment

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

does it also fix flutter/flutter#81875?

Copy link
Member Author

Choose a reason for hiding this comment

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

Half of the problem, there were 2. The position problem and the direct buffer problem.

Copy link

Choose a reason for hiding this comment

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

do we want to remove the ability to set null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, check out where this function is actually used: https://github.com/gaaclarke/engine/blob/7219fc0932a238cee073bb20f19ccd8f8729d022/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java#L160:L161 There is a separate function you are supposed to use if you want to send null.

Copy link

Choose a reason for hiding this comment

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

sg

@jason-simmons
Copy link
Member

It might also make sense to add an FML_DCHECK() that verifies a non-null address to the GetDirectBufferAddress calls in platform_view_android.cc

@blasten
Copy link

blasten commented May 5, 2021

@gaaclarke for documentation, it already mentions that a direct ByteBuffer is expected. Maybe, it can also say that an exception is thrown. Also, null is supported.

* @param reply the reply payload, a direct-allocated {@link ByteBuffer} or null. Senders of

@gaaclarke
Copy link
Member Author

@gaaclarke for documentation, it already mentions that a direct ByteBuffer is expected. Maybe, it can also say that an exception is thrown. Also, null is supported.

* @param reply the reply payload, a direct-allocated {@link ByteBuffer} or null. Senders of

Yea, but the problem with that is if you look at the reproduction code, it isn't clear that you are actually using a BinaryMessenger.
From the users perspective you are using a BasicMessageChannel, a DartExecutor, and a BinaryCodec. They'd have to do some digging to actually see that comment. But it would be weird somewhere else too.

@gaaclarke
Copy link
Member Author

gaaclarke commented May 5, 2021

It might also make sense to add an FML_DCHECK() that verifies a non-null address to the GetDirectBufferAddress calls in platform_view_android.cc

@jason-simmons thanks, done

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM assuming there's a test

@gaaclarke gaaclarke added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 5, 2021
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Windows Android AOT Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Windows Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Windows UWP Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 5, 2021
@gaaclarke gaaclarke added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 12, 2021
@gaaclarke gaaclarke force-pushed the direct-buffer-exception branch from c0a15a0 to 28b214a Compare May 12, 2021 18:21
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite build_and_test_linux_unopt_debug has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 12, 2021
@gaaclarke gaaclarke merged commit f7c3e7e into flutter:master May 12, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 13, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 13, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 13, 2021
cbracken pushed a commit to flutter/flutter that referenced this pull request May 13, 2021
* 67b046e Update documentation for embedding SplashScreen (flutter/engine#25943)

* a0a7203 Set exitcode to 0 on successful uwptool launch (flutter/engine#26105)

* ecb367f Roll Skia from 0270bf5d10be to 4e9d5e2bdf04 (5 revisions) (flutter/engine#26102)

* 85bcce7 Roll Dart SDK from 934cc986926d to 171876a4e6cf (2 revisions) (flutter/engine#26101)

* b99a362 Roll Fuchsia Mac SDK from GNyjTge9c... to q1qWG9XiN... (flutter/engine#26107)

* f7c3e7e Added exception if you try to reply with a non-direct ByteBuffer. (flutter/engine#25952)

* 96ec5a5 Roll Skia from 4e9d5e2bdf04 to 84f70136abfb (4 revisions) (flutter/engine#26108)

* 2c3c1df Use a comma-separated args string for UWP (flutter/engine#26110)

* 25c06a4 Roll Skia from 84f70136abfb to 66441d4ea0fa (2 revisions) (flutter/engine#26111)

* d21a04b Roll Skia from 66441d4ea0fa to 537b7508343d (1 revision) (flutter/engine#26113)

* aeb98f4 Roll Fuchsia Linux SDK from MoY7UVVro... to WYD7atCH7... (flutter/engine#26116)

* 08d9bc0 Revert "Sped up the objc standard message codec (#25998)" (flutter/engine#26117)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants