Repository: flutter
Issue: FormatException: Message corrupted in StandardMessageCodec.readValue during state restoration
Labels: c: crash,framework,P3,a: state restoration,needs repro info,has partial patch,team-framework,triaged-framework

### Steps to reproduce

Can't reproduce, but my app is using simple restorable variables (RestorableString, etc.) and navigator.restorablePush functions.

### Expected results

Shouldn't crash during state restoration.
This is a very rare problem.

### Actual results

App crashes on iOS during fresh app start very rarely.
The error is "FormatException: Message corrupted" in StandardMessageCodec.readValue (you can see it in the logs below) during state restoration. I have no other logs, as the app crashes immediately (at state restoration), none of my code runs.

As writing an incorrect value to a restorable variable would cause an error while modifying the variable, and an error like that doesn't occur, I believe this is a bug in Flutter.

### Code sample

<details open><summary>Code sample</summary>

```dart
Navigator.of(context).restorablePush(ConversationPage.routeBuilder,
                arguments: {'conversation': conversation.toJSON()});
```

```dart
late RestorableTextEditingController inputController;
RestorableInt replyMessageId = RestorableInt(0);
  RestorableString chatInput = RestorableString("");
RestorableBool isSendingImage = RestorableBool(false);
```

```dart
 @override
  void initState() {
    super.initState();

    inputController = RestorableTextEditingController();
}
```

```dart
@override
  void dispose() {
    inputController.dispose();
    super.dispose();
  }
```

```dart
@override
  void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
    registerForRestoration(chatInput, 'chatInput');
    registerForRestoration(inputController, 'inputController');
    registerForRestoration(replyMessageId, 'replyMessageId');
    registerForRestoration(isSendingImage, 'isSendingImage');

    String savedInput =
        context.read<DataCubit>().chatInputs[widget.conversation.id] ?? "";
    if (inputController.value.text.isEmpty && savedInput.isNotEmpty) {
      inputController.value.text = savedInput;
      chatInput.value = savedInput;
    }
  }
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

![437038965_411982418270517_8298018276426356937_n](https://github.com/flutter/flutter/assets/9161775/ef0039e8-c199-4b36-9fe9-ba5a5073fe8c)

</details>


### Logs

<details open><summary>Logs</summary>

```
Fatal Exception: FlutterError
0  ???                            0x0 StandardMessageCodec.readValue + 474 (message_codecs.dart:474)
1  ???                            0x0 StandardMessageCodec.decodeMessage + 341 (message_codecs.dart:341)
2  ???                            0x0 RestorationManager._decodeRestorationData + 322 (restoration.dart:322)
3  ???                            0x0 RestorationManager.handleRestorationUpdateFromEngine + 276 (restoration.dart:276)
4  ???                            0x0 RestorationManager._parseAndHandleRestorationUpdateFromEngine + 243 (restoration.dart:243)
5  ???                            0x0 RestorationManager._getRootBucketFromEngine + 239 (restoration.dart:239)
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale hu-HU)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      flutter config --android-sdk to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google [Chrome.app/Contents/MacOS/Google](http://chrome.app/Contents/MacOS/Google) Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] VS Code (version 1.88.1)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 3 categories.
```

</details>