authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2026-01-29 23:28:20+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-30 08:19:50+01:00
logb9819fce69e0f208e9e20071071a40863fbdb8a9
tree15842468312224bba89ec2b5488d980c4a0f536d
parent380ea6fb5eea659200d496540efea1fa4e39dcaf

Io.Threaded: limit copy_file_range len to prevent EOVERFLOW


1 files changed, 7 insertions(+), 3 deletions(-)

lib/std/Io/Threaded.zig+7-3
......@@ -9675,10 +9675,12 @@ fn fileWriteFileStreaming(
96759675 file_reader.interface.toss(n -| header.len);
96769676 return n;
96779677 }
9678 var len: usize = @intFromEnum(limit);
96789679 var off_in: i64 = undefined;
96799680 const off_in_ptr: ?*i64 = switch (file_reader.mode) {
96809681 .positional_simple, .streaming_simple => return error.Unimplemented,
96819682 .positional => p: {
9683 len = @min(len, std.math.maxInt(usize) - file_reader.pos);
96829684 off_in = @intCast(file_reader.pos);
96839685 break :p &off_in;
96849686 },
......@@ -9689,7 +9691,7 @@ fn fileWriteFileStreaming(
96899691 .linux => n: {
96909692 const syscall: Syscall = try .start();
96919693 while (true) {
9692 const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, null, @intFromEnum(limit), 0);
9694 const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, null, len, 0);
96939695 switch (linux_copy_file_range_sys.errno(rc)) {
96949696 .SUCCESS => {
96959697 syscall.finish();
......@@ -9849,10 +9851,12 @@ fn fileWriteFilePositional(
98499851 file_reader.interface.toss(n -| header.len);
98509852 return n;
98519853 }
9854 var len: usize = @min(@intFromEnum(limit), std.math.maxInt(usize) - offset);
98529855 var off_in: i64 = undefined;
98539856 const off_in_ptr: ?*i64 = switch (file_reader.mode) {
98549857 .positional_simple, .streaming_simple => return error.Unimplemented,
98559858 .positional => p: {
9859 len = @min(len, std.math.maxInt(usize) - file_reader.pos);
98569860 off_in = @intCast(file_reader.pos);
98579861 break :p &off_in;
98589862 },
......@@ -9864,7 +9868,7 @@ fn fileWriteFilePositional(
98649868 .linux => n: {
98659869 const syscall: Syscall = try .start();
98669870 while (true) {
9867 const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, &off_out, @intFromEnum(limit), 0);
9871 const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, &off_out, len, 0);
98689872 switch (linux_copy_file_range_sys.errno(rc)) {
98699873 .SUCCESS => {
98709874 syscall.finish();
......@@ -9888,7 +9892,7 @@ fn fileWriteFilePositional(
98889892 .IO => return error.InputOutput,
98899893 .NOMEM => return error.SystemResources,
98909894 .NOSPC => return error.NoSpaceLeft,
9891 .OVERFLOW => return error.Unseekable,
9895 .OVERFLOW => |err| errnoBug(err), // We avoid passing too large a count.
98929896 .NXIO => return error.Unseekable,
98939897 .SPIPE => return error.Unseekable,
98949898 .PERM => return error.PermissionDenied,