fs: incorrect handling of numeric times from before the unix epoch
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず提供された JavaScript の再現コードを実行し、次にリンク先の行にある lib/internal/fs/utils.js を調べます。数値の負の utimes 値がどのように処理されるかを追跡し、Unix エポックより前の想定されるタイムスタンプを確認するとともに、issue の -1000 と -1500 の記述を解決します。数値の負の時刻が現在時刻にならなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 68/100