You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fs.readSync does not validate invalid position type (accepts object instead of throwing) #62638
I would like to report a behavior in Node that can be reproduced by running the below snippet
"use strict"importfsfrom'node:fs';importosfrom'node:os';importpathfrom'node:path';constmemPath=fs.mkdtempSync(path.join(os.tmpdir(),'node-temp-'));constmemFile=path.join(memPath,'tempfile');fs.writeFileSync(memFile,'');// Open the file for reading and writingconstfd=fs.openSync(memFile,'r+');constankor=newTextEncoder().encode('');// This call is intentionally incorrect: `position` should be a number or null.try{fs.readSync(fd,ankor,0,ankor.length,{not: 'a number'}/* invalid position */);console.log('fs.readSync did not throw as expected');}catch(err){console.log('fs.readSync threw an error as expected:',errinstanceofTypeError ? 'TypeError' : err.name,'-',err.message);}fs.closeSync(fd);
How often does it reproduce? Is there a required condition?
No special condition for reproduction
What is the expected behavior? Why is that the expected behavior?
root@KContainer:~/14128# deno run -A poc.mjs
fs.readSync threw an error as expected: TypeError - The "position" argument must be of type bigint or integer. Received an instance of Object
What do you see instead?
Does not throw even in strict mode
root@KContainer:~/14128# node poc.mjs
fs.readSync did not throw as expected
Activity
geeksilva97 commentedon Apr 8, 2026
The validation is lazy. It reaches the case where
length === 0and early returns.To match the behavior with the docs, we should either update the docs or move the validation upwards.
damianremington274-blip commentedon Apr 8, 2026