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

io::copy() might be trying to use invalid file descriptor #122052

Closed
jkarneges opened this issue Mar 6, 2024 · 3 comments
Closed

io::copy() might be trying to use invalid file descriptor #122052

jkarneges opened this issue Mar 6, 2024 · 3 comments
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@jkarneges
Copy link
Contributor

jkarneges commented Mar 6, 2024

Code:

use std::fs;

fn main() {
    fs::copy("foo", "bar").unwrap();
}

If I ensure "foo" exists and run the above program under valgrind on Linux, I get:

==75959== Warning: invalid file descriptor -1 in syscall copy_file_range(fd_in)()

The docs say copy_file_range may be used on Linux. Maybe it is used incorrectly? The file does get copied though.

This warning appears when the program is built with stable (1.76.0) and nightly.

@jkarneges jkarneges added the C-bug Category: This is a bug. label Mar 6, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2024
@tbu-
Copy link
Contributor

tbu- commented Mar 6, 2024

This seems to be intentional and not a bug:

let result = unsafe {
cvt(copy_file_range(INVALID_FD, ptr::null_mut(), INVALID_FD, ptr::null_mut(), 1, 0))
};

It's probing whether the syscall copy_file_range exists.

tbu- added a commit to tbu-/rust that referenced this issue Mar 6, 2024
If it's obvious from the actual syscall results themselves that the
syscall is supported or unsupported, don't do an extra syscall with an
invalid file descriptor.

CC rust-lang#122052
tbu- added a commit to tbu-/rust that referenced this issue Mar 6, 2024
If it's obvious from the actual syscall results themselves that the
syscall is supported or unsupported, don't do an extra syscall with an
invalid file descriptor.

CC rust-lang#122052
@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue May 26, 2024
…8472

Less syscalls for the `copy_file_range` probe

If it's obvious from the actual syscall results themselves that the syscall is supported or unsupported, don't do an extra syscall with an invalid file descriptor.

CC rust-lang#122052
@Enselic
Copy link
Member

Enselic commented Nov 12, 2024

Triage: Since this behavior seemingly is intentional, let's close as "not a bug".

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
@tbu-
Copy link
Contributor

tbu- commented Nov 12, 2024

It was also changed in #122079 to only trigger in the error case. The example program will no longer trigger the invalid file descriptor warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants