Repository: flutter
Issue: [file_selector] Selecting very large files on Android causes OOM crash
Labels: c: crash,package,P2,c: fatal crash,p: file_selector,team-android,triaged-android

### Steps to reproduce

I opened a 300 MB file on the Android side using a component, and the application crashed. This happened multiple times.

### Expected results

App crashes

### Actual results

```
Throwing OutOfMemoryError "Failed to allocate a 346750536 byte allocation with 100663296 free bytes and 178MB until OOM, target footprint 450734840, growth limit 536870912" (VmSize 12973952 kB)

E/AndroidRuntime(20784): java.lang.OutOfMemoryError: Failed to allocate a 346750536 byte allocation with 100663296 free bytes and 178MB until OOM, target footprint 450734840, growth limit 536870912
E/AndroidRuntime(20784): 	at java.util.Arrays.copyOf(Arrays.java:3670)
E/AndroidRuntime(20784): 	at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:120)
E/AndroidRuntime(20784): 	at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:95)
E/AndroidRuntime(20784): 	at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:156)
``` 

### Code sample

<details open><summary>Code sample</summary>

```dart
final List<XFile> files = await openFiles();
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details><summary>Details</summary>
<p>

```
[✓] Flutter (Channel stable, 3.16.5, on macOS 13.5.2 22G91 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.16.5 on channel stable at /Users/kevin/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (2 weeks ago), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/kevin/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/kevin/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[✓] Connected device (3 available)
    • 2304FPN6DC (mobile) • a2329c3d • android-arm64  • Android 13 (API 33)
    • macOS (desktop)     • macos    • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)        • chrome   • web-javascript • Google Chrome 120.0.6099.199

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
``` 

</p>
</details>