-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
We observed an issue in which a File.copySync in the Flutter CLI resulted in a file of the correct size, but with a tail of '0' bytes in the case where the program is killed by a signal. The tail of '0' bytes exposed insufficient input validation in package:kernel leading to OOM crashes:
@jensjoha investigated with some small programs, and observed the tail of '0' bytes only on Windows. For large file copies, the Windows documentation recommends using the COPY_FILE_NO_BUFFERING flag, but the flag by itself is not sufficient to avoid the issue in the case that the process is killed or the whole system dies (e.g. loses power).
The blog post here recommends copying a file to a temporary location, and then renaming the file to its file destination. We can do this in the Flutter CLI, but this method should really be used by dart:io so that all Dart users can benefit.