Skip to content

File.copy{Sync} on Windows should copy to a temporary file, then rename it. #42119

@zanderso

Description

@zanderso

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:

flutter/flutter#54420
#41862

@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.

/cc @mraleph @a-siva @zichangg @jonasfj

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ioos-windows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions