Skip to content

Commit

Permalink
node:fs: windows: fix integer cast truncating bits when using too lar…
Browse files Browse the repository at this point in the history
…ge of a mode (#17249)
  • Loading branch information
nektro authored Feb 11, 2025
1 parent 321500c commit 251c2b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ pub const FileSystemFlags = enum(c_int) {
return ctx.throwValue(ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.asNumber()}).toJS());
}
const number = val.coerce(i32, ctx);
return @as(FileSystemFlags, @enumFromInt(@as(Mode, @intCast(@max(number, 0)))));
return @as(FileSystemFlags, @enumFromInt(@max(number, 0)));
}

const jsType = val.jsType();
Expand Down
14 changes: 14 additions & 0 deletions test/js/node/fs/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3646,3 +3646,17 @@ describe('kernel32 long path conversion does not mangle "../../path" into "path"
});
}
});

it("overflowing mode doesn't crash", () => {
// this is easiest to test on windows since mode_t is a u16 there
expect(() => openSync("./a.txt", 65 * 1024)).toThrow(
expect.objectContaining({
name: "Error",
message: `ENOENT: no such file or directory, open './a.txt'`,
code: "ENOENT",
syscall: "open",
// errno: -4058,
path: "./a.txt",
}),
);
});

0 comments on commit 251c2b7

Please sign in to comment.