From 21d582a3cd971f0c1737aeccfccaffab6810367e Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Thu, 13 Nov 2025 15:19:18 -0800 Subject: [PATCH] fix(createEmptyObject) fix some createEmptyObject values (#22512) ### What does this PR do? We must use the right number of properties (not more or less) or we should set it to 0 ### How did you verify your code works? Read the code, this will avoid potencial crashs and improve stability --- src/bun.js/api/bun/h2_frame_parser.zig | 2 +- src/bun.js/api/bun/socket/tls_socket_functions.zig | 2 +- src/bun.js/node/node_os.zig | 6 +++--- src/s3/list_objects.zig | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bun.js/api/bun/h2_frame_parser.zig b/src/bun.js/api/bun/h2_frame_parser.zig index 4e7f86db3b..de5f88a2a9 100644 --- a/src/bun.js/api/bun/h2_frame_parser.zig +++ b/src/bun.js/api/bun/h2_frame_parser.zig @@ -3028,7 +3028,7 @@ pub const H2FrameParser = struct { var stream = this.streams.getPtr(stream_id) orelse { return globalObject.throw("Invalid stream id", .{}); }; - var state = jsc.JSValue.createEmptyObject(globalObject, 7); + var state = jsc.JSValue.createEmptyObject(globalObject, 6); state.put(globalObject, jsc.ZigString.static("localWindowSize"), jsc.JSValue.jsNumber(stream.windowSize)); state.put(globalObject, jsc.ZigString.static("state"), jsc.JSValue.jsNumber(@intFromEnum(stream.state))); diff --git a/src/bun.js/api/bun/socket/tls_socket_functions.zig b/src/bun.js/api/bun/socket/tls_socket_functions.zig index 1c8ea80325..1330d208d1 100644 --- a/src/bun.js/api/bun/socket/tls_socket_functions.zig +++ b/src/bun.js/api/bun/socket/tls_socket_functions.zig @@ -383,9 +383,9 @@ pub fn getEphemeralKeyInfo(this: *This, globalObject: *jsc.JSGlobalObject, _: *j if (this.isServer()) { return JSValue.jsNull(); } - var result = JSValue.createEmptyObject(globalObject, 3); const ssl_ptr = this.socket.ssl() orelse return JSValue.jsNull(); + var result = JSValue.createEmptyObject(globalObject, 0); // TODO: investigate better option or compatible way to get the key // this implementation follows nodejs but for BoringSSL SSL_get_server_tmp_key will always return 0 diff --git a/src/bun.js/node/node_os.zig b/src/bun.js/node/node_os.zig index 9da343a975..f4bd9eee52 100644 --- a/src/bun.js/node/node_os.zig +++ b/src/bun.js/node/node_os.zig @@ -92,7 +92,7 @@ fn cpusImplLinux(globalThis: *jsc.JSGlobalObject) !jsc.JSValue { times.irq = scale * try std.fmt.parseInt(u64, toks.next() orelse return error.eol, 10); // Actually create the JS object representing the CPU - const cpu = jsc.JSValue.createEmptyObject(globalThis, 3); + const cpu = jsc.JSValue.createEmptyObject(globalThis, 1); cpu.put(globalThis, jsc.ZigString.static("times"), times.toValue(globalThis)); try values.putIndex(globalThis, num_cpus, cpu); @@ -511,7 +511,7 @@ fn networkInterfacesPosix(globalThis: *jsc.JSGlobalObject) bun.JSError!jsc.JSVal num_inet_interfaces += 1; } - var ret = jsc.JSValue.createEmptyObject(globalThis, 8); + var ret = jsc.JSValue.createEmptyObject(globalThis, 0); // Second pass through, populate each interface object it = interface_start; @@ -522,7 +522,7 @@ fn networkInterfacesPosix(globalThis: *jsc.JSGlobalObject) bun.JSError!jsc.JSVal const addr = std.net.Address.initPosix(@alignCast(@as(*std.posix.sockaddr, @ptrCast(iface.ifa_addr)))); const netmask = std.net.Address.initPosix(@alignCast(@as(*std.posix.sockaddr, @ptrCast(iface.ifa_netmask)))); - var interface = jsc.JSValue.createEmptyObject(globalThis, 7); + var interface = jsc.JSValue.createEmptyObject(globalThis, 0); // address The assigned IPv4 or IPv6 address // cidr The assigned IPv4 or IPv6 address with the routing prefix in CIDR notation. If the netmask is invalid, this property is set to null. diff --git a/src/s3/list_objects.zig b/src/s3/list_objects.zig index 9238719d3b..c862041588 100644 --- a/src/s3/list_objects.zig +++ b/src/s3/list_objects.zig @@ -118,7 +118,7 @@ pub const S3ListObjectsV2Result = struct { const jsContents = try JSValue.createEmptyArray(globalObject, contents.items.len); for (contents.items, 0..) |item, i| { - const objectInfo = JSValue.createEmptyObject(globalObject, 1); + const objectInfo = JSValue.createEmptyObject(globalObject, 0); objectInfo.put(globalObject, jsc.ZigString.static("key"), try bun.String.createUTF8ForJS(globalObject, item.key)); if (item.etag) |etag| { @@ -146,7 +146,7 @@ pub const S3ListObjectsV2Result = struct { } if (item.owner) |owner| { - const jsOwner = JSValue.createEmptyObject(globalObject, 2); + const jsOwner = JSValue.createEmptyObject(globalObject, 0); if (owner.id) |id| { jsOwner.put(globalObject, jsc.ZigString.static("id"), try bun.String.createUTF8ForJS(globalObject, id)); } @@ -168,7 +168,7 @@ pub const S3ListObjectsV2Result = struct { const jsCommonPrefixes = try JSValue.createEmptyArray(globalObject, common_prefixes.items.len); for (common_prefixes.items, 0..) |prefix, i| { - const jsPrefix = JSValue.createEmptyObject(globalObject, 1); + const jsPrefix = JSValue.createEmptyObject(globalObject, 0); jsPrefix.put(globalObject, jsc.ZigString.static("prefix"), try bun.String.createUTF8ForJS(globalObject, prefix)); try jsCommonPrefixes.putIndex(globalObject, @intCast(i), jsPrefix); }