fs: preserve readFile() errors when using a numeric fd and buffer option

Aperta
#64,367 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
javascript, node.js

Direzione di ricerca

Inizia eseguendo la riproduzione JavaScript fornita su Node.js, quindi esamina lib/internal/fs/read/context.js intorno alle righe 180-194, in particolare ReadFileContext.close(err) per i descrittori di file forniti dall’utente. Il lavoro è completato quando la chiamata con un fd numerico e un buffer troppo piccolo segnala ERR_INVALID_ARG_VALUE invece di completarsi correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

fs
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.

Lingua principale
JavaScript
Stelle
122k
Fork
37.4k
Merge medio
4g 3h
PR unite (30g)
273

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node

Tutte le issue di nodejs/node

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.