Skip to content

fs: read Node's mode and flag ladders in the sync fs calls - #3540

Open
ctate wants to merge 14 commits into
mainfrom
ctate/fs-read-node-812253
Open

ctate wants to merge 14 commits into
mainfrom
ctate/fs-read-node-812253

Conversation

@ctate

@ctate ctate commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator
  • fs.openSync, fs.mkdirSync, fs.chmodSync and fs.fchmodSync accept the modes and flags Node accepts, including octal strings, numeric open(2) bits and O_* masks, and run Node's validation ladder at run time for any/union arguments instead of refusing them; the callback fs.open takes numeric flags and the 0o666 default.
  • Four differential programs (node24-fs-open-sync.ts, node24-fs-mkdir-sync.ts, node24-fs-modes-sync.ts, node24-fs-callback-numeric-flags.cjs) pin the behavior and its error codes against Node in the plain and sanitized lanes; the compatibility ledger and docs are regenerated.
  • No compatibility row changes status; the batch widens the behavior and evidence behind rows that remain partial.

openSync, mkdirSync, chmodSync and fchmodSync now accept the modes Node's
parseFileMode accepts, an octal string or an integer in 0..2^32-1, and an
argument whose static type is any or a union runs Node's validation ladder
at run time instead of being refused by the build. openSync takes a string
flag name or raw open(2) bits (an inline fs.constants.O_* mask is mapped to
the target's bits), mkdirSync answers the first directory a recursive walk
created and accepts the mode as the options argument itself, and every check
throws Node's error with its code and message.

The callback fs.open ladder accepts numeric flags through validateInt32 and
parseFileMode, and an omitted, null or undefined mode opens with 0o666 as in
Node. Octal strings that parse past 0xffffffff throw ERR_OUT_OF_RANGE.

Differential corpus: node24-fs-open-sync.ts, node24-fs-mkdir-sync.ts,
node24-fs-modes-sync.ts and node24-fs-callback-numeric-flags.cjs, each with
a corpus-cost file; ts7 order baselines recorded.
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Nov 13, 2026 1:41am UTC

Comment thread packages/runtime/src/scr_bytes_io.c Resolved
? "fs.mkdirObjVoidSync"
: "fs.mkdirObjSync";
return { kind: "libCall", fn, args: [path, mode, recursive], type, loc };
}

@vercel vercel Bot Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a recursive-first mkdirSync initializer mutates the variable used for mode, the fast path still reads mode before running that initializer and creates the directory with stale permissions.

Fix on Vercel

@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

Comment thread packages/runtime/src/scr_bytes_io.c Resolved
Comment thread packages/runtime/src/scr_bytes_io.c Resolved
Comment thread packages/runtime/src/scr_bytes_io.c Resolved
Comment thread packages/runtime/src/scr_bytes_io.c Resolved

This branch was successfully deployed

1 active deployment
Preview — d046ed18 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant