From b196dd1d7958aee86095bd06190eee484a562488 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 26 Nov 2021 19:33:42 +0100 Subject: [PATCH] std.system: fix slice bounds in preadMin() If a partial read occurs past the halfway point, buf.len - i will be less than i, which is illegal. The end bound is also entirely unecessary in this case, so just remove it. --- lib/std/zig/system.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 19df6bda0b..f76382ae2d 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -922,7 +922,7 @@ pub const NativeTargetInfo = struct { fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize { var i: usize = 0; while (i < min_read_len) { - const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) { + const len = file.pread(buf[i..], offset + i) catch |err| switch (err) { error.OperationAborted => unreachable, // Windows-only error.WouldBlock => unreachable, // Did not request blocking mode error.NotOpenForReading => unreachable,