do_sendfile() returns EOVERFLOW when a positive-count request starts at the effective file size limit. If the input file ends exactly at that limit, this rejects the final EOF probe even though no bytes remain to be copied. For example, Python 3.12 shutil.copyfile() copies all 4294967295 bytes of a maximum-size FAT32 file to ext4, then raises EOVERFLOW on its next sendfile() call instead of completing successfully. Allow the boundary position when it matches the input file size. The existing clamp then reduces count to zero and the remaining validation is retained. Continue to reject positions beyond the limit and boundary positions with input data still remaining. Signed-off-by: Hungyu Lin --- fs/read_write.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 4da846a2bf17..a25e23c6a327 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1347,7 +1347,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes); if (unlikely(pos + count > max)) { - if (pos >= max) + if (pos > max || + (pos == max && pos != i_size_read(in_inode))) return -EOVERFLOW; count = max - pos; } -- 2.43.0