nodejs / nodejs/node

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

未关闭
#64,597 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的 JavaScript 复现程序,然后检查链接行中的 lib/internal/fs/utils.js。跟踪数值型负 utimes 值的处理方式,并验证 Unix 纪元之前的预期时间戳,解决 issue 中 -1000 与 -1500 的表述问题。数值型负时间不再变成当前时间即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。