-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
fs::copy() linux: handle sparse files and set file mode early #58636
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
d9df8b9
to
58e4ee2
Compare
A convenience method like fs::copy() should try to prevent pitfalls a normal user doesn't think about. In case of an empty umask, setting the file mode early prevents temporarily world readable or even writeable files, because the default mode is 0o666. In case the target is a named pipe or special device node, setting the file mode can lead to unwanted side effects, like setting permissons on `/dev/stdout` or for root setting permissions on `/dev/null`. Not handling sparse files could fill up the users disk very quickly. Fixes: rust-lang#26933 rust-lang#37885 rust-lang#58635
Rust doesn't support kernels older than 2.6 (https://forge.rust-lang.org/platform-support.html). I don't object to the check being there but something else is likely to break before anyone gets to this code. |
Thanks for the PR! We actually had a different request for this as well recently, but I think the verdict is still the same as before. We're not currently in a position to maintain complicated maintenance of file copying to this degree. This sort of algorithm would be perfect for crates.io, however! Would you be ok to slim down this PR to just the bug fixes aside from the sparse file handling? |
If handling sparse files is out of scope by design then it should probably be mentioned in |
Fix for the non-sparse version: |
Would it help if this PR would add a test to prevent this from breaking again? |
☔ The latest upstream changes (presumably #58208) made this pull request unmergeable. Please resolve the merge conflicts. |
@alexcrichton yeah, close this, if sparse files won't be handled. |
Ok! |
A convenience method like fs::copy() should try to prevent pitfalls a
normal user doesn't think about.
In case of an empty umask, setting the file mode early prevents
temporarily world readable or even writeable files,
because the default mode is 0o666.
In case the target is a named pipe or special device node, setting the
file mode can lead to unwanted side effects, like setting permissons on
/dev/stdout
or for root setting permissions on/dev/null
.Not handling sparse files could fill up the users disk very quickly.
Fixes:
#26933
#37885
#58635