Repository navigation
Read validator input on Windows without O_NOFOLLOW - #55
Closed
julian27sg wants to merge 1 commit into
Closed
julian27sg wants to merge 1 commit into
julian27sg wants to merge 1 commit into
Conversation
Node leaves O_NOFOLLOW and O_NONBLOCK undefined on win32, so readFileWithinLimit rejected every input before reading a byte and neither validator CLI could run there at all. POSIX is unchanged and still takes the race-free open. Windows now lstats the path with bigint stats, rejects a symlink, a non-regular file and an ino of 0n, opens read-only, and rejects the descriptor when ino or dev no longer match. Bigint matters here: NTFS file IDs exceed 2^53, where two adjacent IDs share one double and the compare would pass on a swapped file. The branch is weaker than O_NOFOLLOW. openSync follows the reparse point before the compare rejects, so the target is opened and never read, and O_NONBLOCK has no Windows analogue. Where the file index is unavailable it fails closed exactly as the code does today. Refs #53.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the direction proposed in #53. The approach and the analysis there are that issue's; this is the implementation and the measurements.
Problem
Node leaves
O_NOFOLLOWandO_NONBLOCKundefined on win32, soreadFileWithinLimitrefuses every input before reading a byte:Phase 4 validation cannot run natively on Windows at all. #31, #38, #48 and #49 make the failure quieter or better explained; none makes the validators run.
Change
POSIX is untouched: where both constants exist, the original
O_RDONLY | O_NOFOLLOW | O_NONBLOCKopen runs exactly as before and the new branch is never reached.On win32:
lstatSync(file, { bigint: true }), reject a symlink, a non-regular file, orino === 0n.openSync(file, O_RDONLY).fstatSync(fd, { bigint: true }), reject unlessinoanddevstill match step 1.isFile(), size and UTF-8 checks are unchanged.Every other platform without the two constants keeps the current hard rejection.
Why bigint
NTFS file IDs exceed 2^53, where adjacent integers share one double:
Adjacent MFT records are the normal case, so a Number-based compare could pass on a swapped file. Bigint stats remove that.
Measured
Node 24.13.1 on Windows 11:
The skips are the existing
HAS_SAFE_INPUT_OPENand win32 guards, which this change does not touch.Four inputs per validator (empty array, top-level object, malformed JSON, partial record) produce byte-identical stdout and exit codes against unmodified upstream running on Linux.
The patched files still pass 34/34 and 31/31 on Linux with no skips, so the POSIX path shows no regression.
What this does not do
openSyncfollows the reparse point before the compare rejects, so the target is opened and never read. This is weaker thanO_NOFOLLOW, which refuses the open itself.O_NONBLOCKhas no Windows analogue, so a path that blocks on open is not guarded.HAS_SAFE_INPUT_OPEN, deliberately left unchanged so this does not collide with Fix CLI test suite hanging failures on platforms without O_NOFOLLOW/O_NONBLOCK #31 and test: guard the remaining CLI tests behind HAS_SAFE_INPUT_OPEN #38. Happy to add swap-detection,ino === 0nand symlink tests if you want them here rather than in a follow-up.ino === 0ncheck is what keeps those failing closed.