std::io::Write::write_vectored() does not properly limit the number of iovecs. #68042
Labels
C-bug
Category: This is a bug.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
The callers of
std::io::Write::write_vectored()
should not have to go through the effort of determining what the maximum number of iovec structures can be passed to the underlying system call. As demonstrated by this example:The output is:
The underlying system call of writev() has limit on the number of iovec items that can be passed specifically the man page for writev() has
When running on Mac OS X it appears the libc implementation is not doing the extra work of determining the limit of the number of items that can be used in one call of writev(). On Mac OS X this limit is defined by
UIO_MAXIOV
.Looking at the unix implementation of write_vectored it seems that line 113 is the problem.
rust/src/libstd/sys/unix/fd.rs
Lines 108 to 117 in 3982d35
The code that assumes the upper limit of the number of iovecs being passed can equal
c_int::max_value()
is too large. It should either be limited toUID_MAXIOV
on Max OS X or the result ofsysconf(_SC_IOV_MAX)
on Linux.Changing this logic will help the logic work such that any number of IoSlices can be passed to
io::std::Write::write_vectored()
.The text was updated successfully, but these errors were encountered: