From 0367f18cb9dc61090c27e29572a50810b9809822 Mon Sep 17 00:00:00 2001 From: poypoyan Date: Sat, 12 Oct 2024 03:32:10 +0800 Subject: [PATCH] std.mem.readVarInt: assert ReturnType is large enough (#20946) Fixes #20521 --- lib/std/mem.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/mem.zig b/lib/std/mem.zig index d458e26989..65d801a0aa 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1602,6 +1602,7 @@ test containsAtLeast { /// T specifies the return type, which must be large enough to store /// the result. pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType { + assert(@typeInfo(ReturnType).int.bits >= bytes.len * 8); const bits = @typeInfo(ReturnType).int.bits; const signedness = @typeInfo(ReturnType).int.signedness; const WorkType = std.meta.Int(signedness, @max(16, bits));