fs: preserve readFile() errors when using a numeric fd and buffer option
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
v24.18.0
Platform
Windows 11 x64
Subsystem
fs
What steps will reproduce the bug?
'use strict';
const fs = require('node:fs');
fs.writeFileSync('repro.txt', 'Hello world');
fs.open('repro.txt', 'r', (err, fd) => {
if (err) throw err;
fs.readFile(fd, { buffer: Buffer.alloc(5) }, (err, data) => {
console.log('err:', err && err.code);
console.log('data:', data && data.toString());
fs.closeSync(fd);
});
});
How often does it reproduce? Is there a required condition?
Always, when fs.readFile() is called with:
a numeric file descriptor, and
options.buffer, and
the supplied buffer is too small for the file
What is the expected behavior? Why is that the expected behavior?
The call should fail with ERR_INVALID_ARG_VALUE because the provided buffer is too small to contain the full file contents.
What do you see instead?
The error is dropped for user-supplied file descriptors, and the callback can complete successfully instead of reporting ERR_INVALID_ARG_VALUE.
Additional information
Root cause appears to be in lib/internal/fs/read/context.js (lines 180-194): ReadFileContext.close(err) ignores err when isUserFd is true, so the final callback runs as if no failure occurred.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された JavaScript の再現コードを Node.js で実行し、次に lib/internal/fs/read/context.js の 180-194 行付近、特にユーザーのファイルディスクリプターに対する ReadFileContext.close(err) を調べます。数値 fd とサイズ不足のバッファーを使った呼び出しが正常に完了せず、ERR_INVALID_ARG_VALUE を報告すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 74/100