fs: incorrect handling of numeric times from before the unix epoch
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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