mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:24:33 +01:00
Io.Threaded: limit copy_file_range len to prevent EOVERFLOW
This commit is contained in:
parent
380ea6fb5e
commit
b9819fce69
1 changed files with 7 additions and 3 deletions
|
|
@ -9675,10 +9675,12 @@ fn fileWriteFileStreaming(
|
|||
file_reader.interface.toss(n -| header.len);
|
||||
return n;
|
||||
}
|
||||
var len: usize = @intFromEnum(limit);
|
||||
var off_in: i64 = undefined;
|
||||
const off_in_ptr: ?*i64 = switch (file_reader.mode) {
|
||||
.positional_simple, .streaming_simple => return error.Unimplemented,
|
||||
.positional => p: {
|
||||
len = @min(len, std.math.maxInt(usize) - file_reader.pos);
|
||||
off_in = @intCast(file_reader.pos);
|
||||
break :p &off_in;
|
||||
},
|
||||
|
|
@ -9689,7 +9691,7 @@ fn fileWriteFileStreaming(
|
|||
.linux => n: {
|
||||
const syscall: Syscall = try .start();
|
||||
while (true) {
|
||||
const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, null, @intFromEnum(limit), 0);
|
||||
const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, null, len, 0);
|
||||
switch (linux_copy_file_range_sys.errno(rc)) {
|
||||
.SUCCESS => {
|
||||
syscall.finish();
|
||||
|
|
@ -9849,10 +9851,12 @@ fn fileWriteFilePositional(
|
|||
file_reader.interface.toss(n -| header.len);
|
||||
return n;
|
||||
}
|
||||
var len: usize = @min(@intFromEnum(limit), std.math.maxInt(usize) - offset);
|
||||
var off_in: i64 = undefined;
|
||||
const off_in_ptr: ?*i64 = switch (file_reader.mode) {
|
||||
.positional_simple, .streaming_simple => return error.Unimplemented,
|
||||
.positional => p: {
|
||||
len = @min(len, std.math.maxInt(usize) - file_reader.pos);
|
||||
off_in = @intCast(file_reader.pos);
|
||||
break :p &off_in;
|
||||
},
|
||||
|
|
@ -9864,7 +9868,7 @@ fn fileWriteFilePositional(
|
|||
.linux => n: {
|
||||
const syscall: Syscall = try .start();
|
||||
while (true) {
|
||||
const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, &off_out, @intFromEnum(limit), 0);
|
||||
const rc = linux_copy_file_range_sys.copy_file_range(in_fd, off_in_ptr, out_fd, &off_out, len, 0);
|
||||
switch (linux_copy_file_range_sys.errno(rc)) {
|
||||
.SUCCESS => {
|
||||
syscall.finish();
|
||||
|
|
@ -9888,7 +9892,7 @@ fn fileWriteFilePositional(
|
|||
.IO => return error.InputOutput,
|
||||
.NOMEM => return error.SystemResources,
|
||||
.NOSPC => return error.NoSpaceLeft,
|
||||
.OVERFLOW => return error.Unseekable,
|
||||
.OVERFLOW => |err| errnoBug(err), // We avoid passing too large a count.
|
||||
.NXIO => return error.Unseekable,
|
||||
.SPIPE => return error.Unseekable,
|
||||
.PERM => return error.PermissionDenied,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue