nodejs / nodejs/node

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

Đang mở
#64,597 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy trình tái hiện JavaScript được cung cấp, sau đó kiểm tra lib/internal/fs/utils.js tại các dòng được liên kết. Theo dõi cách các giá trị utimes âm dạng số được xử lý và xác minh dấu thời gian dự kiến trước epoch Unix, làm rõ cách diễn đạt -1000 so với -1500 trong issue. Hoàn tất khi các thời gian âm dạng số không còn trở thành thời gian hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.