nodejs / nodejs/node

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

Offen
#64,597 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

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

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führe zunächst den bereitgestellten JavaScript-Reproducer aus und untersuche anschließend lib/internal/fs/utils.js an den verlinkten Zeilen. Verfolge, wie numerische negative utimes-Werte verarbeitet werden, und überprüfe den erwarteten Zeitstempel vor der Unix-Epoche, wobei die Formulierung -1000 versus -1500 im Issue geklärt werden soll. Als erledigt gilt die Änderung, wenn numerische negative Zeiten nicht mehr zur aktuellen Zeit werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.