copy_cat() is doing unnecessary math to derive the maximum size allowed by the copy_file_range() syscall. This calculates an excessively big number which is 0x7FFFFFFFC0000000. Linux syscalls have a much lower limit for single I/O operations, which is defined in kernel as `INT_MAX - PAGE_SIZE`, so lower the limit to that.
evidence of the limit is shown below:
$ uname -a
Linux v 6.17.5 #191 SMP Thu Oct 23 21:43:33 CEST 2025 x86_64 GNU/Linux
$ ll random
-rw-r--r-- 1 teknoraver users 8.0G Dec 12 19:19 random
$ strace -e copy_file_range src/cat random >random2
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 2147479552
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 2147479552
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 2147479552
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 2147479552
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 16384
copy_file_range(3, NULL, 1, NULL, 9223372035781033984, 0) = 0
--
Matteo Croce
perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplay
copy_file_range_2147479552.patch
Description: Binary data
