Re: sendfile(2) erroneously yields EINVAL on too large counts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 2024-03-04 14:52, Alejandro Colomar wrote:
>> 
>> which sounds an awful lot like the documented EOVERFLOW behavior:
>> 
>>        EOVERFLOW
>>               count is too large, the operation would result in
>>               exceeding the maximum size of either the input file or
>>               the output file.
>> 
>> but the reported error is EINVAL rather than EOVERFLOW.  Moreover, the
>> (actual) result from this testcase does not go above a few bytes
>> anyhow, so should not signal an overflow anyway.
>
>The kernel detects that offset+count would overflow, and aborts early.
>That's actually a good thing.  Otherwise, we wouldn't have noticed that
>the program is missing an lseek(2) call until much later.
>addition of count+offset would cause overflow, that is, undefined
>behavior, it's better to not even start.  Otherwise, it gets tricky to
>write code that doesn't invoke UB.

While offset+count would overflow arithmetically, if the file is not larger
than SSIZE_MAX, that should be just fine, because sendfile() stops at EOF
like read() and does not read beyond EOF or produce extraneous NULs
to the point that a huge file position would come about.




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux