From 18f322c5327fa2a4682d2ba7cd3c2215dbc5372c Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 8 Aug 2024 15:38:54 +0200 Subject: [PATCH] Throw an error when running out of DevId numbers I find it hard to imagine that this will happen on a real filesystem, but it can be triggered by a malicious export file. Better protect against that than invoke undefined behavior. --- src/model.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/model.zig b/src/model.zig index 6dd119f..9ab7cd0 100644 --- a/src/model.zig +++ b/src/model.zig @@ -346,6 +346,7 @@ pub const devices = struct { defer lock.unlock(); const d = lookup.getOrPut(dev) catch unreachable; if (!d.found_existing) { + if (list.items.len >= std.math.maxInt(DevId)) ui.die("Maximum number of device identifiers exceeded.\n", .{}); d.value_ptr.* = @as(DevId, @intCast(list.items.len)); list.append(dev) catch unreachable; }