Skip to content

std::fs::copy returns the combined size of all streams on NTFS on Windows #44532

Closed
@stephaneyfx

Description

@stephaneyfx

NTFS files may contain alternate data streams besides the main one. Since PR #26751, std::fs::copy returns the combined size of all streams, which is confusing and likely unexpected unless the user is aware of this Windows/NTFS peculiarity.

An example where Windows uses alternate data streams seems to be when storing whether a file was downloaded from the internet (e.g. to display a security section and an "Unblock" button in the file properties). Such alternate streams are more like metadata, and to be consistent with other file metadata (attributes, permissions, extended attributes, etc.), their size should not be reflected in the value returned by copy.

In summary, I think std::fs::copy should return the size of the main stream for the following reasons (alternate data streams are still copied, their size is just not reported, like other metadata):

  • This is the least confusing result for non-NTFS experts and what most people expect (no "copying more bytes than the file contains").
  • This is consistent with other file metadata whose size is not reported by copy.
  • Alternate streams are mostly invisible, unless you try to open them explicitly. Even the file properties don't show them and Windows reports only the size of the main stream in the dialog.

@retep998, what do you think?

Steps to reproduce

  1. On Windows, download an executable file to a NTFS partition and verify that the property dialog contains a security section with an "Unblock" button.
  2. Note the file size reported in the file properties.
  3. Copy the file to the same partition using std::fs::copy and note the number of bytes returned.

Expected result

The number of bytes copied reported by copy is equal to the file size.

Actual result

copy reports a number of bytes greater than the file size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsP-mediumMedium priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions