Skip to content

Conversation

@rpkak
Copy link
Contributor

@rpkak rpkak commented Oct 29, 2025

EOVERFLOW The requested source or destination range is too large to represent in the specified data types.

This error occurs if limit is .unlimited (std.math.maxInt(usize)) and the pos field of the reader/writer is not 0.

Example 1 (uses preadv after copy_file_range)
const std = @import("std");

pub fn main() !void {
    const path_from = std.os.argv[1];
    const path_to = std.os.argv[2];
    const from = try std.fs.cwd().openFile(std.mem.span(path_from), .{});
    defer from.close();
    const to = try std.fs.cwd().createFile(std.mem.span(path_to), .{});
    defer to.close();
    var buf: [4096]u8 = undefined;
    var reader = from.reader(&.{});
    var writer = to.writer(&buf);
    defer writer.interface.flush() catch {};

    _ = try reader.interface.streamRemaining(&writer.interface);
}
$ zig build-exe test.zig
$ ./test test.zig out

strace before this PR:

openat(AT_FDCWD, "test.zig", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 3
openat(AT_FDCWD, "out", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 4
copy_file_range(3, [0], 4, [0], 18446744073709551615, 0) = 535
copy_file_range(3, [535], 4, [535], 18446744073709551615, 0) = -1 EOVERFLOW (Value too large for defined data type)
preadv(3, [{iov_base="", iov_len=4096}], 1, 535) = 0
close(4)                                = 0
close(3)                                = 0

strace with this PR:

openat(AT_FDCWD, "test.zig", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 3
openat(AT_FDCWD, "out", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 4
copy_file_range(3, [0], 4, [0], 18446744073709551615, 0) = 535
copy_file_range(3, [535], 4, [535], 18446744073709551080, 0) = 0
close(4)                                = 0
close(3)                                = 0
Example 2 (uses preadv/pwritev instead of copy_file_range)
const std = @import("std");

pub fn main() !void {
    const path_from = std.os.argv[1];
    const path_to = std.os.argv[2];
    const from = try std.fs.cwd().openFile(std.mem.span(path_from), .{});
    defer from.close();
    const to = try std.fs.cwd().createFile(std.mem.span(path_to), .{});
    defer to.close();
    var buf: [4096]u8 = undefined;
    var reader = from.reader(&.{});
    var writer = to.writer(&buf);
    defer writer.interface.flush() catch {};

    // Change the seek position of writer or reader (or both)
    try reader.interface.discardAll(1);

    _ = try reader.interface.streamRemaining(&writer.interface);
}
$ zig build-exe test.zig
$ ./test test.zig out

strace before this PR:

openat(AT_FDCWD, "test.zig", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 3
openat(AT_FDCWD, "out", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 4
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_TYPE|STATX_MODE|STATX_ATIME|STATX_MTIME|STATX_CTIME, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=638, ...}) = 0
copy_file_range(3, [1], 4, [0], 18446744073709551615, 0) = -1 EOVERFLOW (Value too large for defined data type)
preadv(3, [{iov_base="onst std = @import(\"std\");\n\npub "..., iov_len=4096}], 1, 1) = 637
preadv(3, [{iov_base="", iov_len=3459}], 1, 638) = 0
pwritev(4, [{iov_base="onst std = @import(\"std\");\n\npub "..., iov_len=637}], 1, 0) = 637
close(4)                                = 0
close(3)                                = 0

strace with this PR:

openat(AT_FDCWD, "test.zig", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 3
openat(AT_FDCWD, "out", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 4
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_TYPE|STATX_MODE|STATX_ATIME|STATX_MTIME|STATX_CTIME, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=638, ...}) = 0
copy_file_range(3, [1], 4, [0], 18446744073709551614, 0) = 637
close(4)                                = 0
close(3)                                = 0

.failure => return error.WriteFailed,
};
const n = copy_file_range(in_fd, off_in_ptr, out_fd, off_out_ptr, @intFromEnum(limit), 0) catch |err| {
const n = copy_file_range(in_fd, off_in_ptr, out_fd, off_out_ptr, len, 0) catch |err| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I should make EOVERFLOW unreachable here. Tell me if I should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant