nodejs / nodejs/node

fs: incorrect handling of numeric times from before the unix epoch

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

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

https://github.com/nodejs/node/blob/4f844f4380a143d0c24b39d1df34b187b06619ae/lib/internal/fs/utils.js#L783-L793

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

  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.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.