Skip to content

flutter attach crashes with FormatException #31854

Closed
flutter/packages
#20

Description

@LinusU

flutter attach crashes basically as soon as I start it. I'm suspecting it might be encountering some strange mDNS record which makes it crash, since I'm currently on a large corporate network. Will try again tonight at home to see if it's reproducible there.

Steps to Reproduce

  1. flutter attach

Logs

[  +41 ms] executing: [/Users/linus/coding/flutter/] git log -n 1 --pretty=format:%H
[  +44 ms] Exit code 0 from: git log -n 1 --pretty=format:%H
[        ] 0ba67226ee62d6c9d663a6f8410fb4b2f1076046
[        ] executing: [/Users/linus/coding/flutter/] git describe --match v*.*.* --first-parent --long --tags
[  +98 ms] Exit code 0 from: git describe --match v*.*.* --first-parent --long --tags
[        ] v1.5.8-0-g0ba67226e
[  +16 ms] executing: [/Users/linus/coding/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +15 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/dev
[        ] executing: [/Users/linus/coding/flutter/] git ls-remote --get-url origin
[  +15 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +78 ms] executing: [/Users/linus/coding/flutter/] git rev-parse --abbrev-ref HEAD
[  +13 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] dev
[ +457 ms] executing: /usr/local/share/android-sdk/platform-tools/adb devices -l
[  +13 ms] Exit code 0 from: /usr/local/share/android-sdk/platform-tools/adb devices -l
[        ] List of devices attached
[   +7 ms] executing: idevice_id -h
[ +175 ms] executing: which ideviceinstaller
[   +8 ms] Exit code 0 from: which ideviceinstaller
[        ] /usr/local/bin/ideviceinstaller
[        ] executing: which iproxy
[   +5 ms] Exit code 0 from: which iproxy
[        ] /usr/local/bin/iproxy
[   +6 ms] /usr/bin/xcrun simctl list --json devices
[ +353 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +6 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FuchsiaCacheArtifacts' is not required, skipping update.
[ +144 ms] Checking for advertised Dart observatories...
Unhandled exception:
FormatException: Bad UTF-8 encoding 0xc (at offset 22)
#0      _Utf8Decoder.convert (dart:convert/utf.dart:444:15)
#1      Utf8Decoder.convert (dart:convert/utf.dart:327:13)
#2      Utf8Codec.decode (dart:convert/utf.dart:59:56)
#3      _readFQDN (package:multicast_dns/src/packet.dart:165:24)
#4      decodeMDnsResponse.readResourceRecord (package:multicast_dns/src/packet.dart:240:36)
#5      decodeMDnsResponse (package:multicast_dns/src/packet.dart:350:55)
#6      MDnsClient._handleIncoming (package:multicast_dns/multicast_dns.dart:194:45)
#7      _rootRunUnary (dart:async/zone.dart:1136:13)
#8      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#9      _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#11     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#12     _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#13     _StreamController._add (dart:async/stream_controller.dart:640:7)
#14     _StreamController.add (dart:async/stream_controller.dart:586:5)
#15     new _RawDatagramSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1859:33)
#16     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:844:14)
#17     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#18     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#19     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:115:13)
#20     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:5)

Flutter doctor output:

[✓] Flutter (Channel dev, v1.5.8, on Mac OS X 10.14.4 18E226, locale en-GB)
    • Flutter version 1.5.8 at /Users/linus/coding/flutter
    • Framework revision 0ba67226ee (6 days ago), 2019-04-24 17:18:28 -0700
    • Engine revision c63d1cf9c9
    • Dart version 2.3.0 (build 2.3.0-dev.0.1 1f1592edce)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /usr/local/share/android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /usr/local/share/android-sdk
    • ANDROID_SDK_ROOT = /usr/local/share/android-sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.33.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.25.1

[✓] Connected device (1 available)
    • Linus Unnebäck’s iPhone • f94aa6361e142ab9641a700b2eb487e8611738f4 • ios • iOS 12.2

• No issues found!

Activity

  1. added
    c: crashStack traces logged to the console
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Apr 30, 2019
  2. LinusU commented on May 1, 2019

    @LinusU
    Author

    Interestingly enough, it seems to be at different offset every time I run the command 🤔

    Out of 500 tries:

       1 FormatException: Bad UTF-8 encoding 0xc (at offset 40)
       1 FormatException: Bad UTF-8 encoding 0xc (at offset 55)
       1 Invalid argument(s): Invalid internet address 0
       1 Oops; flutter has exited unexpectedly.
       2 FormatException: Bad UTF-8 encoding 0xc (at offset 8)
       4 FormatException: Bad UTF-8 encoding 0xc (at offset 7)
       4 FormatException: Bad UTF-8 encoding 0xc (at offset 13)
       4 FormatException: Bad UTF-8 encoding 0xc (at offset 27)
       8 FormatException: Bad UTF-8 encoding 0xc (at offset 6)
       8 FormatException: Bad UTF-8 encoding 0xc (at offset 16)
       9 FormatException: Bad UTF-8 encoding 0xc (at offset 18)
      11 FormatException: Bad UTF-8 encoding 0x99 (at offset 19)
      12 FormatException: Bad UTF-8 encoding 0xc (at offset 15)
      15 FormatException: Bad UTF-8 encoding 0xc (at offset 5)
      17 FormatException: Bad UTF-8 encoding 0xc (at offset 25)
      17 FormatException: Bad UTF-8 encoding 0xc (at offset 28)
      18 FormatException: Bad UTF-8 encoding 0xc (at offset 14)
      27 FormatException: Bad UTF-8 encoding 0xc (at offset 24)
      29 FormatException: Bad UTF-8 encoding 0xc (at offset 17)
      30 FormatException: Bad UTF-8 encoding 0xc (at offset 21)
      31 FormatException: Bad UTF-8 encoding 0xc (at offset 22)
      38 FormatException: Bad UTF-8 encoding 0xc (at offset 19)
      55 FormatException: Bad UTF-8 encoding 0xc (at offset 26)
      61 FormatException: Bad UTF-8 encoding 0xc (at offset 23)
      96 FormatException: Bad UTF-8 encoding 0xc (at offset 20)
    
  3. blasten commented on May 1, 2019

    @blasten

    @LinusU Thanks for the logs. I was wondering if you could add some print statements to dump the packet that is causing the issue.

    This is the patch I have been working on flutter/packages@master...blasten:catch-format-exception.

    Steps:

    1. cd ~/.pub-cache/hosted/pub.dartlang.org/multicast_dns-*/lib/src/

    2. mv packet.dart _packet.dart

    3. curl https://raw.githubusercontent.com/blasten/packages/815c8251c5136665ea4f5c237d5cb82885ecd7d1/packages/multicast_dns/lib/src/packet.dart --output packet.dart

    4. which flutter | sed "s/flutter$/cache\/flutter_tools\.snapshot/" | xargs rm

    5. Run flutter attach again.

    6. Send us the packet: "The source bytes were: ..."

    7. mv ~/.pub-cache/hosted/pub.dartlang.org/multicast_dns-*/lib/src/_packet.dart ~/.pub-cache/hosted/pub.dartlang.org/multicast_dns-*/lib/src/packet.dart

    Let me know if this doesn't work.

  4. LinusU commented on May 2, 2019

    @LinusU
    Author

    Those are really detailed instructions, thanks! I was looking at that PR, but wasn't sure on how to test it out locally...

    Applying the changes gives me an entirely different error though 🤔 I think I saw this when disconnecting from the wifi with the previous build...

    I did do another test just before applying the patch, and that gave me the same error as always. Will try to de-apply the patch and see if it comes back...

    edit: yes, de-applying the patch brings back the original UTF8 error

    command

    flutter attach

    exception

    NoSuchMethodError: NoSuchMethodError: The getter 'port' was called on null.
    Receiver: null
    Tried calling: port

    #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
    #1      AttachCommand.runCommand (package:flutter_tools/src/commands/attach.dart:219:78)
    <asynchronous suspension>
    #2      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:488:18)
    #3      _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:77:64)
    #4      _rootRunUnary (dart:async/zone.dart:1132:38)
    #5      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    #6      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
    #7      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
    #8      Future._propagateToListeners (dart:async/future_impl.dart:668:32)
    #9      Future._complete (dart:async/future_impl.dart:473:7)
    #10     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
    #11     _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async-patch/async_patch.dart:33:20)
    #12     _rootRun (dart:async/zone.dart:1124:13)
    #13     _CustomZone.run (dart:async/zone.dart:1021:19)
    #14     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
    #15     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
    #16     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
    #17     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:115:13)
    #18     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:5)
    

    flutter doctor

    �[32m[✓]�[39m Flutter (Channel dev, v1.5.8, on Mac OS X 10.14.4 18E226, locale en-GB)
        �[32m•�[39m Flutter version 1.5.8 at /Users/linus/coding/flutter
        �[32m•�[39m Framework revision 0ba67226ee (7 days ago), 2019-04-24 17:18:28 -0700
        �[32m•�[39m Engine revision c63d1cf9c9
        �[32m•�[39m Dart version 2.3.0 (build 2.3.0-dev.0.1 1f1592edce)
    
    �[32m[✓]�[39m Android toolchain - develop for Android devices (Android SDK version 28.0.3)
        �[32m•�[39m Android SDK at /usr/local/share/android-sdk
        �[32m•�[39m Android NDK location not configured (optional; useful for native profiling support)
        �[32m•�[39m Platform android-28, build-tools 28.0.3
        �[32m•�[39m ANDROID_HOME = /usr/local/share/android-sdk
        �[32m•�[39m ANDROID_SDK_ROOT = /usr/local/share/android-sdk
        �[32m•�[39m Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        �[32m•�[39m Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
        �[32m•�[39m All Android licenses accepted.
    
    �[32m[✓]�[39m iOS toolchain - develop for iOS devices (Xcode 10.2.1)
        �[32m•�[39m Xcode at /Applications/Xcode.app/Contents/Developer
        �[32m•�[39m Xcode 10.2.1, Build version 10E1001
        �[32m•�[39m ios-deploy 1.9.4
        �[32m•�[39m CocoaPods version 1.6.1
    
    �[32m[✓]�[39m Android Studio (version 3.2)
        �[32m•�[39m Android Studio at /Applications/Android Studio.app/Contents
        �[32m•�[39m Flutter plugin version 31.3.1
        �[32m•�[39m Dart plugin version 181.5656
        �[32m•�[39m Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    
    �[32m[✓]�[39m VS Code (version 1.33.1)
        �[32m•�[39m VS Code at /Applications/Visual Studio Code.app/Contents
        �[32m•�[39m Flutter extension version 2.25.1
    
    �[32m[✓]�[39m Connected device (1 available)
        �[32m•�[39m Linus Unnebäck’s iPhone • f94aa6361e142ab9641a700b2eb487e8611738f4 • ios • iOS 12.2
    
    �[32m•�[39m No issues found!
    
  5. LinusU commented on May 2, 2019

    @LinusU
    Author

    Okay, I managed to just edit the file in place and found a lot of offending parts. Looking at the data it seems like there is some problem with the offset/lengths into the backing data. Basically, the data in each part printed would look something like this:

    ck...s MacBook Pro. . (several non-ascii bytes) Linu

    But with other names, presumably of other people working in the same co-working space as me. Because of that I didn't want to share the raw packets publicly here, but I'd be happy to share them privately with you, just let me know where to send them.

    The Uint8Lists passed to utf8.decode seems to 1) start not where the string should start (i.e. if the name of my computer is "Linus Unnebäck's MacBook Pro" it will start several bytes into that string, and 2) have too many bytes so that it includes other binary data after the string, and also part of the next entry after that (i.e. it will have the end of one name, then some binary data, and then the start of another name, or even an entire other entry, and then the start of a third).

    Some observations:

    • There seem to always be 15 bytes of data between UTF8-encoded names of computers.
    • The last of that byte seems to be the byte length of the next name
    • The data passed for decoding can cut of both in the middle of names, and in the middle of the 15 bytes data between names
    • The 15 bytes of data between names seems to always start with C00CC00C 000C0001 00000E
    • Some names where included multiple times, so it seems like the data passed for decoding can sometimes span the same source bytes.
    • The first packet could be off by only one byte, since it starts with a common name without the first letter, and then "MacBook Pro"
    • Aha! 👏 the first packet is very probably off by one byte, because the utf8 encoding of the first character that was missing from the name, is the same as the length of that data passed in! This is probably the root cause...

    @blasten it seems like there is an off-by-one error when reading the first name length, making everything else after that read from basically random places in the data

  6. dnfield commented on May 2, 2019

    @dnfield
    Contributor

    The first error was another bug we fixed yesterday.

    The second is interesting. It would be very helpful if you could somehow get a sanitized reproduction of the packet (s) causing this

  7. dnfield commented on May 2, 2019

    @dnfield
    Contributor

    I'm willing to bet there's somewhere we assume we can advance by one byte but there's a multibyte character were going into the middle of

  8. blasten commented on May 2, 2019

    @blasten

    @LinusU Thanks for looking into it! The entire packet will be very useful. Feel free to send it to me in a DM via our Slack channel: https://fluttercommunity.slack.com - Search for Emmanuel.

  9. blasten commented on May 3, 2019

    @blasten

    I think I found the fix to the bug @dnfield : blasten/packages@5785eb5

    @LinusU would you mind trying this out?

  10. LinusU commented on May 3, 2019

    @LinusU
    Author

    Tried it out, it reads the length one byte too early instead of too late now 😆

    Sending you packets on Slack 👌

  11. blasten commented on May 3, 2019

    @blasten

    I noted I missed this commit: blasten/packages@bb88fd3. The last packet you sent me seems to be passing with this last change.

  12. LinusU commented on May 3, 2019

    @LinusU
    Author

    With that one, everything seems to work 🙌

    Now I'm getting to the NoSuchMethodError: The getter 'port' was called on null. problem instead, but I think that's fixed on master 👌

  13. dnfield commented on May 3, 2019

    @dnfield
    Contributor

    Let's leave this open until the fix lands in the framework.

  14. reopened this on May 3, 2019
  15. blasten commented on May 6, 2019

    @blasten

    This issue is fixed in master now 🎉

  16. Bluelich commented on Jun 6, 2019

    @Bluelich

    @blasten when will you merge this change to the stable branch? The version of stable channel is v1.5.4-hotfix.2 now

  17. dnfield commented on Jun 6, 2019

    @dnfield
    Contributor

    @Bluelich this fix is available on the current beta. If it's important to your workflow, you should probably just start using the beta. It will eventually roll into stable, and it's very rare that any changes are made from when it's in beta to when it's in stable.

    See https://github.com/flutter/flutter/wiki/Flutter-build-release-channels#which-channel-should-i-use for more details on how to pick which channel to use, and a bit more details about the cadence at which stable releases are normally made.

  18. blasten commented on Jun 6, 2019

    @blasten

    +1 to what @dnfield said. Also, from: https://groups.google.com/forum/#!topic/flutter-announce/oIzwT9EDczc:

    we expect to have a beta release in late June (which will go to stable by early July)

  19. github-actions commented on Aug 29, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  20. locked as resolved and limited conversation to collaborators on Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consoletoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions