mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
copy_file_range: limit len to prevent EOVERFLOW
This commit is contained in:
parent
a7119d4269
commit
dea342cba3
1 changed files with 4 additions and 1 deletions
|
|
@ -1926,9 +1926,11 @@ pub const Writer = struct {
|
||||||
return sendFileBuffered(io_w, file_reader, reader_buffered);
|
return sendFileBuffered(io_w, file_reader, reader_buffered);
|
||||||
var off_in: i64 = undefined;
|
var off_in: i64 = undefined;
|
||||||
var off_out: i64 = undefined;
|
var off_out: i64 = undefined;
|
||||||
|
var len: usize = @intFromEnum(limit);
|
||||||
const off_in_ptr: ?*i64 = switch (file_reader.mode) {
|
const off_in_ptr: ?*i64 = switch (file_reader.mode) {
|
||||||
.positional_reading, .streaming_reading => return error.Unimplemented,
|
.positional_reading, .streaming_reading => return error.Unimplemented,
|
||||||
.positional => p: {
|
.positional => p: {
|
||||||
|
len = @min(len, std.math.maxInt(usize) - file_reader.pos);
|
||||||
off_in = @intCast(file_reader.pos);
|
off_in = @intCast(file_reader.pos);
|
||||||
break :p &off_in;
|
break :p &off_in;
|
||||||
},
|
},
|
||||||
|
|
@ -1938,13 +1940,14 @@ pub const Writer = struct {
|
||||||
const off_out_ptr: ?*i64 = switch (w.mode) {
|
const off_out_ptr: ?*i64 = switch (w.mode) {
|
||||||
.positional_reading, .streaming_reading => return error.Unimplemented,
|
.positional_reading, .streaming_reading => return error.Unimplemented,
|
||||||
.positional => p: {
|
.positional => p: {
|
||||||
|
len = @min(len, std.math.maxInt(usize) - w.pos);
|
||||||
off_out = @intCast(w.pos);
|
off_out = @intCast(w.pos);
|
||||||
break :p &off_out;
|
break :p &off_out;
|
||||||
},
|
},
|
||||||
.streaming => null,
|
.streaming => null,
|
||||||
.failure => return error.WriteFailed,
|
.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| {
|
||||||
w.copy_file_range_err = err;
|
w.copy_file_range_err = err;
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue