Replace catch bun.outOfMemory() with safer alternatives (#22141)

Replace `catch bun.outOfMemory()`, which can accidentally catch
non-OOM-related errors, with either `bun.handleOom` or a manual `catch
|err| switch (err)`.

(For internal tracking: fixes STAB-1070)

---------

Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
taylor.fish
2025-08-26 12:50:25 -07:00
committed by GitHub
parent 300f486125
commit 437e15bae5
284 changed files with 1835 additions and 1662 deletions

View File

@@ -73,7 +73,7 @@ pub fn parseUrl(
const base64_data = source[data_prefix.len + ";base64,".len ..];
const len = bun.base64.decodeLen(base64_data);
const bytes = arena.alloc(u8, len) catch bun.outOfMemory();
const bytes = bun.handleOom(arena.alloc(u8, len));
const decoded = bun.base64.decode(bytes, base64_data);
if (!decoded.isSuccessful()) {
return error.InvalidBase64;
@@ -153,7 +153,7 @@ pub fn parseJSON(
var i: usize = 0;
const source_paths_slice = if (hint != .source_only)
alloc.alloc([]const u8, sources_content.items.len) catch bun.outOfMemory()
bun.handleOom(alloc.alloc([]const u8, sources_content.items.len))
else
null;
errdefer if (hint != .source_only) {
@@ -234,7 +234,7 @@ pub fn parseJSON(
break :content null;
}
const str = item.data.e_string.string(arena) catch bun.outOfMemory();
const str = bun.handleOom(item.data.e_string.string(arena));
if (str.len == 0) {
break :content null;
}
@@ -821,7 +821,7 @@ pub const Mapping = struct {
.original = original,
.source_index = source_index,
.name_index = name_index,
}) catch bun.outOfMemory();
}) catch |err| bun.handleOom(err);
}
if (needs_sort and options.sort) {
@@ -1030,7 +1030,7 @@ fn findSourceMappingURL(comptime T: type, source: []const T, alloc: std.mem.Allo
u8 => bun.jsc.ZigString.Slice.fromUTF8NeverFree(url),
u16 => bun.jsc.ZigString.Slice.init(
alloc,
bun.strings.toUTF8Alloc(alloc, url) catch bun.outOfMemory(),
bun.handleOom(bun.strings.toUTF8Alloc(alloc, url)),
),
else => @compileError("Not Supported"),
};