aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Hewitt <davidmhewitt@users.noreply.github.com> 2023-09-12 13:05:00 +0100
committerGravatar GitHub <noreply@github.com> 2023-09-12 05:05:00 -0700
commit07a6443a80d57c2aaa958bafba091bf4f9e88ca8 (patch)
tree004bc2718ca10f003eb31dc091b55528d1b98760
parent6e4f746ace3a42c1a5c9431beba2ae599a6f15b0 (diff)
downloadbun-07a6443a80d57c2aaa958bafba091bf4f9e88ca8.tar.gz
bun-07a6443a80d57c2aaa958bafba091bf4f9e88ca8.tar.zst
bun-07a6443a80d57c2aaa958bafba091bf4f9e88ca8.zip
fix(node/path): Prevent memory corruption in parse (#5083)
* Add failing test for issue #4954 * fix(node/path): Return results with toValueGC
-rw-r--r--src/bun.js/node/types.zig22
-rw-r--r--test/js/node/path/path.test.js11
2 files changed, 18 insertions, 15 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index 51af22052..35daea52c 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -2198,22 +2198,14 @@ pub const Path = struct {
base.setOutputEncoding();
name_.setOutputEncoding();
ext.setOutputEncoding();
- var entries = [10]JSC.ZigString{
- JSC.ZigString.init("dir"),
- JSC.ZigString.init("root"),
- JSC.ZigString.init("base"),
- JSC.ZigString.init("name"),
- JSC.ZigString.init("ext"),
- dir,
- root,
- base,
- name_,
- ext,
- };
- var keys: []JSC.ZigString = entries[0..5];
- var values: []JSC.ZigString = entries[5..10];
- return JSC.JSValue.fromEntries(globalThis, keys.ptr, values.ptr, 5, true);
+ var result = JSC.JSValue.createEmptyObject(globalThis, 5);
+ result.put(globalThis, JSC.ZigString.static("dir"), dir.toValueGC(globalThis));
+ result.put(globalThis, JSC.ZigString.static("root"), root.toValueGC(globalThis));
+ result.put(globalThis, JSC.ZigString.static("base"), base.toValueGC(globalThis));
+ result.put(globalThis, JSC.ZigString.static("name"), name_.toValueGC(globalThis));
+ result.put(globalThis, JSC.ZigString.static("ext"), ext.toValueGC(globalThis));
+ return result;
}
pub fn relative(globalThis: *JSC.JSGlobalObject, isWindows: bool, args_ptr: [*]JSC.JSValue, args_len: u16) callconv(.C) JSC.JSValue {
if (comptime is_bindgen) return JSC.JSValue.jsUndefined();
diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js
index 5865d6182..f18e5c72d 100644
--- a/test/js/node/path/path.test.js
+++ b/test/js/node/path/path.test.js
@@ -812,6 +812,17 @@ describe("path.parse and path.format", () => {
name: "another_dir",
},
},
+ {
+ // https://github.com/oven-sh/bun/issues/4954
+ input: "/test/Ł.txt",
+ expected: {
+ root: "/",
+ dir: "/test",
+ base: "Ł.txt",
+ ext: ".txt",
+ name: "Ł",
+ },
+ }
];
testCases.forEach(({ input, expected }) => {
it(`case ${input}`, () => {