You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dd: remove unsafe from stdin_as_file() by rustix::{io::stdin,stdio::stdin} #12212
This fn is used just for avoiding overreading from stdin. But the unsafe can be logically removed by rustix's read syscall wrapper (at least on unix and wasi).
So we don't need have both of unexpected closing of fd and additional syscall overhead caused by clone.
I mean we can wrap the unsafe to avoid any possible unsoundness, e.g.:
pubstructStdinRaw(ManuallyDrop<File>);#[cfg(not(windows))]pubfnstdin_raw() -> StdinRaw{// SAFETY: We ensure that the file descriptor is never closed by// wrapping the `File` in `ManuallyDrop`.let fd = unsafe{ rustix::stdio::take_stdin()};let f = File::from(fd);StdinRaw(ManuallyDrop::new(f))}
We can't use the safe rustix::io::stdin because we need an OwnedFd not a BorrowedFd to initialize the File.
Activity
xtqqczze commentedon May 10, 2026
#12210 removes
stdin_as_fileand wraps the unsafe in a safeStdinRaw.oech3 commentedon May 11, 2026
It does not remove unsafe from our code base. Just wraps.
xtqqczze commentedon May 11, 2026
I mean we can wrap the unsafe to avoid any possible unsoundness, e.g.:
We can't use the safe
rustix::io::stdinbecause we need anOwnedFdnot aBorrowedFdto initialize theFile.oech3 commentedon May 11, 2026
Bt why do we exactly need
File? seek only?xtqqczze commentedon May 11, 2026
Filehas the convenientRead,WriteandSeektraits that aBorrowedFdlacks.oech3 commentedon May 11, 2026
I could add definition of seek.
xtqqczze commentedon May 11, 2026
Specifically in
dd, we callFile::metadataon stdin, so we need&File.oech3 commentedon May 11, 2026
We can use rustix's API to AsFd instead of std's API