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

Crashes when a large number of files with long file names are selected using pickFiles() on Windows #918

Closed
1 of 4 tasks
bradleybauer opened this issue Dec 13, 2021 · 2 comments · Fixed by #924
Closed
1 of 4 tasks
Assignees
Labels
desktop The issue applies to Windows, Linux or MacOS implementations. new issue An issue that hasn't yet been seen from the maintainer

Comments

@bradleybauer
Copy link

bradleybauer commented Dec 13, 2021

Describe the bug
If a large number of files that have moderately long filenames are selected in pickFiles() then app freezes or crashes.

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
Windows 11

How are you picking?

FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true, allowedExtensions: ['txt'], type: FileType.custom);

Details to reproduce the issue
Create a folder containing an emtpy text file named a.txt
Duplicate a.txt using Ctrl+A, Ctrl+C, Ctrl+V so there is 256 empty text files in the folder.
Create a new project with flutter create test
Replace the floating action button callback with one that calls pickFiles.
Run the flutter project, click the FAB, and in the file picker select all your empty text files and click open.
Observe app failure.
If all 256 txt files are named as 0.txt, 1.txt, 2.txt ... and the folder has a short path like C:\x\ then pickFiles should work as expected.

Error Log
None

Screenshots and/or video
None

Flutter Version details

PS C:\x> flutter doctor -v
[✓] Flutter (Channel stable, 2.8.0, on Microsoft Windows [Version 10.0.22000.348], locale en-US)
    • Flutter version 2.8.0 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cf44000065 (4 days ago), 2021-12-08 14:06:50 -0800
    • Engine revision 40a99c5951
    • Dart version 2.15.0

[✗] 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/windows#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.


[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.7)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31911.196
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] VS Code, 64-bit edition (version 1.63.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.29.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.348]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 96.0.4664.93
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 96.0.1054.43

! Doctor found issues in 2 categories.

Additional context
Replacing 20 with 4000 on this line of code solves the problem for me.

@bradleybauer bradleybauer added the new issue An issue that hasn't yet been seen from the maintainer label Dec 13, 2021
@philenius philenius self-assigned this Dec 14, 2021
@philenius philenius added the desktop The issue applies to Windows, Linux or MacOS implementations. label Dec 14, 2021
@philenius
Copy link
Collaborator

argh, not again 🤐

This issue is related to #831. And yes, you're right, @bradleybauer, this line causes the problem:

final lpstrFileBufferSize = 20 * maximumPathLength;

Last time, I increased it to 20. Let's increase it again and wait for the next person who wants to pick even more files or longer file paths. I'm really wondering what value to set it to.

philenius added a commit that referenced this issue Dec 14, 2021
fixes #918; the buffer lpstrFile stores the paths and file names of the
selected files. As it turns out, 20 * 260 Bytes isn't enough when a
user wants to select > 256 files. Changed the buffer size to
8192 * 260 Bytes (~2.1 MB) which, depending on the file path, is enough
for picking > 2000 files. 8192 * 260 Bytes should fit at minimum
532,480 UTF16 characters. The memory profiler of Flutter DevTools shows
no memory increase while the file picker dialog is open.
Windows Task Manager shows a memory increase of 1 - 2 MB while the file
picker dialog is opened.
@philenius
Copy link
Collaborator

@bradleybauer, I was generous enough to increase the buffer to 8192 * 260 Bytes. That should be enough under most circumstances.

Thanks for reporting this issue. The bug fix will be released shortly as version 4.2.8.

miguelpruivo pushed a commit that referenced this issue Dec 16, 2021
…e-paths-too-small-on-windows

#918: buffer for selected file paths too small on windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop The issue applies to Windows, Linux or MacOS implementations. new issue An issue that hasn't yet been seen from the maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants