fs: remove duplicate fd validation in sync functions

PR-URL: https://github.com/nodejs/node/pull/61361
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
This commit is contained in:
Mert Can Altin authored and Antoine du Hamel committed 2026-01-20 14:36:00 +01:00
1 parent 9f25cad26c
commit 7697ce0310
2 files changed
+20 -17

No files matched your search

-7
View File
@@ -597,7 +597,6 @@ function openAsBlob(path, options = kEmptyObject) {
*/
function read(fd, buffer, offsetOrOptions, length, position, callback) {
fd = getValidatedFd(fd);
let offset = offsetOrOptions;
let params = null;
if (arguments.length <= 4) {
@@ -689,8 +688,6 @@ ObjectDefineProperty(read, kCustomPromisifyArgsSymbol,
* @returns {number}
*/
function readSync(fd, buffer, offsetOrOptions, length, position) {
fd = getValidatedFd(fd);
validateBuffer(buffer);
let offset = offsetOrOptions;
@@ -779,7 +776,6 @@ ObjectDefineProperty(readv, kCustomPromisifyArgsSymbol,
* @returns {number}
*/
function readvSync(fd, buffers, position) {
fd = getValidatedFd(fd);
validateBufferArray(buffers);
if (typeof position !== 'number')
@@ -809,7 +805,6 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
}
fd = getValidatedFd(fd);
let offset = offsetOrOptions;
if (isArrayBufferView(buffer)) {
callback ||= position || length || offset;
@@ -880,7 +875,6 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
* @returns {number}
*/
function writeSync(fd, buffer, offsetOrOptions, length, position) {
fd = getValidatedFd(fd);
const ctx = {};
let result;
@@ -970,7 +964,6 @@ ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, {
* @returns {number}
*/
function writevSync(fd, buffers, position) {
fd = getValidatedFd(fd);
validateBufferArray(buffers);
if (buffers.length === 0) {
+20 -10
View File
@@ -2314,8 +2314,10 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 4);
CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();
int fd;
if (!GetValidatedFd(env, args[0]).To(&fd)) {
return;
}
CHECK(Buffer::HasInstance(args[1]));
Local<Object> buffer_obj = args[1].As<Object>();
@@ -2381,8 +2383,10 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 3);
CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();
int fd;
if (!GetValidatedFd(env, args[0]).To(&fd)) {
return;
}
CHECK(args[1]->IsArray());
Local<Array> chunks = args[1].As<Array>();
@@ -2441,8 +2445,10 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 4);
CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();
int fd;
if (!GetValidatedFd(env, args[0]).To(&fd)) {
return;
}
const int64_t pos = GetOffset(args[2]);
@@ -2634,8 +2640,10 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 5);
CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();
int fd;
if (!GetValidatedFd(env, args[0]).To(&fd)) {
return;
}
CHECK(Buffer::HasInstance(args[1]));
Local<Object> buffer_obj = args[1].As<Object>();
@@ -2765,8 +2773,10 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
const int argc = args.Length();
CHECK_GE(argc, 3);
CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();
int fd;
if (!GetValidatedFd(env, args[0]).To(&fd)) {
return;
}
CHECK(args[1]->IsArray());
Local<Array> buffers = args[1].As<Array>();