fs: preserve readFile() errors when using a numeric fd and buffer option
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit, die bereitgestellte JavaScript-Reproduktion auf Node.js auszuführen. Untersuchen Sie anschließend lib/internal/fs/read/context.js im Bereich der Zeilen 180–194, insbesondere ReadFileContext.close(err) für vom Benutzer bereitgestellte Dateideskriptoren. Als erledigt gilt die Aufgabe, wenn der Aufruf mit einer numerischen fd und einem zu kleinen Puffer ERR_INVALID_ARG_VALUE meldet, anstatt erfolgreich abgeschlossen zu werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, node.js
- Bereich
- operating-systems
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 74/100