-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.statSync, fs.stat and fs.promises.stat returns 'Invalid Date' for atime/ctime/mtime with negative epoch time #43707
Comments
@nodejs/fs |
It's a signed-to-unsigned conversion bug:
Internally, the stats are handed off from C++ to JS in a BigUint64Array but that makes negative values wrap around. The fix is to use a BigInt64Array instead. Pull request welcome. edit: in particular, it's this (insidiously misnamed) field: Line 21 in 7d13f5e
And here is where it's converted to a stats object: Lines 534 to 545 in 7d13f5e
|
Non-bigint stats are returned as |
Sorry yes, I forgot to mention that. That logic is here: Lines 93 to 95 in 7d13f5e
|
Note: on Windows platform, there still is an overflow on negative dates, to postpone Y2038 overflow. |
This allows to support timestamps before 1970-01-01. On Windows, it's not supported due to Y2038 issue. PR-URL: nodejs#43714 Fixes: nodejs#43707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This allows to support timestamps before 1970-01-01. On Windows, it's not supported due to Y2038 issue. PR-URL: nodejs#43714 Fixes: nodejs#43707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Backport-PR-URL: https://github.com/nodejs/node/pull/00000
This allows to support timestamps before 1970-01-01. On Windows, it's not supported due to Y2038 issue. PR-URL: nodejs#43714 Fixes: nodejs#43707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Backport-PR-URL: nodejs#44129
This allows to support timestamps before 1970-01-01. On Windows, it's not supported due to Y2038 issue. PR-URL: nodejs#43714 Fixes: nodejs#43707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Backport-PR-URL: nodejs#44129
This allows to support timestamps before 1970-01-01. On Windows, it's not supported due to Y2038 issue. PR-URL: nodejs#43714 Fixes: nodejs#43707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Version
v16.15.1
Platform
Linux localhost.localdomain 4.18.0-394.el8.x86_64 #1 SMP Tue May 31 16:19:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
File system
What steps will reproduce the bug?
fs.statSync
andfs.promises.stat
for file hogehoge.How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
ctime/mtime/atime with negative epoch time shall be treated as it is.
In other words, if -1 then it shall be 1 second before epoch.
Actually,
Date()
supports negative epoch time.As
stat(2)
supports negative epoch time, which can be observed via ls command, I don't see whyfs.stat
/fs.statSync
/fs.promises.stat
treats negative epoch asNaN
.What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: