Skip to content

Invalid Unicode in TextEditingController's text Crashes the App on iOS #179727

Description

@mahmuttaskiran

Steps to reproduce

App crashes on iOS when a TextField contains malformed Unicode (e.g., half of a surrogate pair such as \u{DFFF}).

Expected results

No crash

Actual results

Crash

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            TextField(
              controller: TextEditingController(text: '\u{DFFF}'),
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: 'Input Text',
                helperText: 'Value: \\u{DFFF}',
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
          Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0xc98c8 __exceptionPreprocess
1  libobjc.A.dylib                0x317c4 objc_exception_throw
2  Foundation                     0x8f3e80 _userInfoForFileAndLine
3  Flutter                        0x4dcfd0 -[FlutterJSONMessageCodec decode:] + 111 (FlutterCodecs.mm:111)
4  Flutter                        0x4dc42c -[FlutterJSONMethodCodec decodeMethodCall:] + 145 (FlutterCodecs.mm:145)
5  Flutter                        0x4d9208 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 312 (FlutterChannels.mm:312)
6  Flutter                        0x6a8e0 invocation function for block in flutter::PlatformMessageHandlerIos::HandlePlatformMessage(std::_fl::unique_ptr<flutter::PlatformMessage, std::_fl::default_delete<flutter::PlatformMessage>>) + 110 (ref_ptr.h:110)
7  libdispatch.dylib              0x1adc _dispatch_call_block_and_release
8  libdispatch.dylib              0x1b7ec _dispatch_client_callout
9  libdispatch.dylib              0x38b24 _dispatch_main_queue_drain.cold.5
10 libdispatch.dylib              0x10ec8 _dispatch_main_queue_drain
11 libdispatch.dylib              0x10e04 _dispatch_main_queue_callback_4CF
12 CoreFoundation                 0x6b520 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 CoreFoundation                 0x1dd14 __CFRunLoopRun
14 CoreFoundation                 0x1cc44 _CFRunLoopRunSpecificWithOptions
15 GraphicsServices               0x1498 GSEventRunModal
16 UIKitCore                      0xa9dcc (Missing UUID 17c42b4970d63ee2aac77010bb917cdc)
17 UIKitCore                      0x4eb0c (Missing UUID 17c42b4970d63ee2aac77010bb917cdc)
18 UIKitCore                      0x18a854 (Missing UUID 17c42b4970d63ee2aac77010bb917cdc)
19 Runner                         0x2f344 main (StandaloneAppDelegate.swift)
20 ???                            0x19a0aae28 (Missing)
        

Flutter Doctor output

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.3, on macOS 15.6.1 24G90 darwin-arm64, locale en-AE)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[!] Xcode - develop for iOS and macOS (Xcode 26.1.1)
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consolec: fatal crashCrashes that terminate the processengineflutter/engine related. See also e: labels.f: material designflutter/packages/flutter/material repository.found in release: 3.38Found to occur in 3.38found in release: 3.40Found to occur in 3.40frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyplatform-macosBuilding on or for macOS specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions