nodejs / nodejs/node

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

Open
#64,597 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided JavaScript reproducer, then inspect lib/internal/fs/utils.js at the linked lines. Trace how numeric negative utimes values are handled and verify the expected pre-Unix-epoch timestamp, resolving the issue’s -1000 versus -1500 wording. Done means numeric negative times no longer become the current time.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.