fs: incorrect handling of numeric times from before the unix epoch
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
Version
v22.16.0
Platform
Linux johnp-pc 7.1.3-200.fc44.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Jul 4 19:20:12 UTC 2026 x86_64 GNU/Linux
Subsystem
node:fs
What steps will reproduce the bug?
Description
Since https://github.com/nodejs/node/commit/1f842c2c613545ba69ad5b9ab48c49ac1f77d8d3, NodeJS internally modifies numeric negative utimes to the current time. This is unexpected, as negative strings ("-1") work as expected. This issue was previously reported, but not all possible types (date, string, number) were considered. and the bug therefore wrongly closed.
Reproducer
import fs from 'node:fs';
const file = 'neg_timespec.txt';
fs.writeFileSync(file, 'test');
// Set time to -1 second before 1970
fs.utimesSync(file, -1, -1);
const stats = fs.statSync(file);
console.log("Expected mtime (ms): -1000");
console.log("Actual mtime (ms): ", stats.mtime.getTime());
fs.unlinkSync(file);
Incorrect code
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
Expected mtime (ms): -1500
What do you see instead?
Actual mtime (ms): 1784465433024
Additional information
Found investigating the Rust port of Bun, where the bug was copied by AI presumably.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore JavaScript fornito, quindi ispeziona lib/internal/fs/utils.js alle righe collegate. Traccia il modo in cui vengono gestiti i valori numerici negativi di utimes e verifica il timestamp previsto precedente all’epoca Unix, risolvendo la formulazione -1000 rispetto a -1500 nell’issue. Il lavoro è completato quando i tempi numerici negativi non diventano più l’ora corrente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript
- Ambito
- operating-systems
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 68/100