fs: incorrect handling of numeric times from before the unix epoch
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando el reproductor de JavaScript proporcionado y, después, inspecciona lib/internal/fs/utils.js en las líneas enlazadas. Traza cómo se gestionan los valores numéricos negativos de utimes y verifica la marca de tiempo esperada anterior a la época Unix, resolviendo la discrepancia entre -1000 y -1500 en la redacción del issue. Se considera terminado cuando los tiempos numéricos negativos ya no se convierten en la hora actual.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- operating-systems
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 68/100