Skip to content

fs.readSync does not validate invalid position type (accepts object instead of throwing) #62638

Description

@kevgeoleo

Version

v24.13.1

Platform

Linux KContainer 5.10.0-12-amd64 #1 SMP Debian 5.10.103-1 (2022-03-07) x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Hi,

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?

Position argument must be a number and error should be thrown
According to the documentation it should be number: https://nodejs.org/api/fs.html#fsreadsyncfd-buffer-offset-length-position

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

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions