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

[pigeon]fix a crash when casting NSNull to an Array #4289

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Jun 23, 2023

Fixes a crash introduced in #3658:

static func fromList(_ list: [Any?]) -> NativeAuthSession? {
  if let userPoolTokensList = list[2] as! [Any?]? {}
}

where list[2] is NSNull, which is not an Optional, hence can't be casted to [Any?]?.

Recall that nilOrValue helper is created for this purpose. So the fix is simply:

static func fromList(_ list: [Any?]) -> NativeAuthSession? {
  if let userPoolTokensList: [Any?] = nilOrValue(list[2]) {} // <- HERE
}

Why didn't we catch this regression

Missing unit tests - we did not test NSNull fields to ensure nilOrValue works for them.

Why did it work in previous version?

It's surprising that this worked fine before! The original code is:

static func fromList(_ list: [Any]) -> NativeAuthSession? {
  if let userPoolTokensList = list[2] as! [Any]? {}
}

From my previous PR, we know that list[2] is an implicit optional (that contains a NSNull value). I think Swift made an exception here when casting implicit optional NSNull (either intentionally or unintentionally).

List which issues are fixed by this PR. You must list at least one issue.

Fixes flutter/flutter#129283

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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 relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@tarrinneal
Copy link
Contributor

There's a unit tests that needs updated to match the new code output.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

I think we're going to need to add collections that contain nulls to the integration tests with this pr as well.

@stuartmorgan
Copy link
Contributor

I think we're going to need to add collections that contain nulls to the integration tests with this pr as well.

Yes, we should definitely add an integration test that covers this. Unit tests are helpful, but can mislead us for Pigeon where we're dealing with cross-language marshalling (e.g., we've had cases where we unit tested both sides of a change, but there was a subtle difference in the protocol so it didn't actually work in practice).

@hellohuanlin
Copy link
Contributor Author

@tarrinneal can you point me to a similar test as an example? (sorry im not yet familiar with this project)

@tarrinneal
Copy link
Contributor

@tarrinneal can you point me to a similar test as an example? (sorry im not yet familiar with this project)

packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart Is where all of our integration tests are run from.

packages/pigeon/pigeons/core_tests.dart is the pigeon definition file that you would update if there isn't already a method that you can use for these tests (which is likely)

and then each platform has it's own implementation code inside the test_plugin folder or alternate_language_test_plugin folders

@tarrinneal
Copy link
Contributor

If you need more specifics I can help with that. If you don't have the bandwidth for this atm I can help as well.

@hellohuanlin
Copy link
Contributor Author

If you don't have the bandwidth for this atm I can help as well.

@tarrinneal that'd be great. i'm indeed fully swamped this week. thanks a lot!

@tarrinneal
Copy link
Contributor

@stuartmorgan think this is enough coverage on the integration tests?

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM with some nits.

packages/pigeon/CHANGELOG.md Outdated Show resolved Hide resolved
packages/pigeon/pigeons/core_tests.dart Show resolved Hide resolved
@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 6, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 6, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jul 6, 2023

auto label is removed for flutter/packages, pr: 4289, due to This PR has not met approval requirements for merging. Changes were requested by {tarrinneal}, please make the needed changes and resubmit this PR.
You are a member of flutter-hackers and need 1 more review(s) in order to merge this PR.

  • Merge guidelines: You need at least one approved review if you are already part of flutter-hackers or two member reviews if you are not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 6, 2023
@auto-submit auto-submit bot merged commit f337050 into flutter:main Jul 6, 2023
69 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 6, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 6, 2023
flutter/packages@7042079...771ec9b

2023-07-06 stuartmorgan@google.com [ci] Enable LUCI Dart unit tests (flutter/packages#4378)
2023-07-06 stuartmorgan@google.com [ci] Bring up LUCI Linux custom package tests (flutter/packages#4382)
2023-07-06 tarrinneal@gmail.com [pigeon] adds generate option for example pigeons (flutter/packages#4370)
2023-07-06 47866232+chunhtai@users.noreply.github.com [go_router] Allows redirect only GoRoute to be part of RouteMatchList (flutter/packages#4315)
2023-07-06 49699333+dependabot[bot]@users.noreply.github.com [sign_in]: Bump com.google.android.gms:play-services-auth from 20.5.0 to 20.6.0 in /packages/google_sign_in/google_sign_in_android/android (flutter/packages#4359)
2023-07-06 41930132+hellohuanlin@users.noreply.github.com [pigeon]fix a crash when casting NSNull to an Array (flutter/packages#4289)
2023-07-06 hello@kamil.id [google_sign_in_web] Fixes force unwrap on values that can be null (flutter/packages#4374)
2023-07-05 engine-flutter-autoroll@skia.org Roll Flutter from 590ef2d to 35085c3 (3 revisions) (flutter/packages#4379)
2023-07-05 43054281+camsim99@users.noreply.github.com [camerax] Fixes `unawaited_futures` violations (flutter/packages#4337)
2023-07-05 stuartmorgan@google.com [ci] Remove `starqlteue` from FTL tests (flutter/packages#4375)
2023-07-05 stuartmorgan@google.com [tools] Switch to `flutter test` (flutter/packages#4348)
2023-07-05 joshuapetitma@yahoo.com [flutter_markdown] Add TableCellVerticalAlignment property in markdown stylesheet (flutter/packages#3880)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pigeon] Crash in swift: Could not cast value of type 'NSNull' to 'NSArray'
3 participants