Skip to content
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

src: make fs functions handle pre-epoch timestamps #32408

Closed
wants to merge 3 commits into from

Conversation

bnoordhuis
Copy link
Member

A wrong type cast prevented timestamps before 1970-01-01 from working
with functions like fs.stat().

Fixes: #32369

The first commit is libuv/libuv#2747. This PR can't land (at least, not without the test failing) until libuv is upgraded.

Introduced in commit 9836cf5 ("lib: lazy instantiation of fs.Stats
dates") without providing any rationale - that wasn't added until later,
by someone else - and it doesn't look the least bit correct to me.

It certainly makes an upcoming regression test fail because a timestamp
in the deep past doesn't round-trip correctly, it's off by a fraction of
a second.

Refs: nodejs#32369
A wrong type cast prevented timestamps before 1970-01-01 from working
with functions like `fs.stat()`.

Fixes: nodejs#32369
@bnoordhuis bnoordhuis added the blocked PRs that are blocked by other issues or PRs. label Mar 21, 2020
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Mar 21, 2020
@nodejs-github-bot
Copy link
Collaborator

@bnoordhuis
Copy link
Member Author

bnoordhuis commented Mar 22, 2020

The AIX failure was to be expected (EINVAL - I'm reasonably sure utimensat() doesn't allow pre-epoch dates) but the Windows failures are interesting:

14:25:42       actual: 2037-02-25T16:25:46.955Z,
14:25:42       expected: 1969-07-20T02:56:00.000Z,

I wonder if there's another bug hiding somewhere...

edit: test/parallel/test-fs-utimes.js now fails on Windows when it tries to set and read back a Y2K38 timestamp, probably no coincidence.

14:25:14       actual: 2147483648,
14:25:14       expected: -2147483648,

edit2: the test mixes up actual and expected:

assert.strictEqual(Y2K38_mtime, Y2K38_stats.mtime.getTime() / 1000);

They should be the other way around:

assert.strictEqual(Y2K38_stats.mtime.getTime() / 1000, Y2K38_mtime);

I.e., actual === -2147483648 and expected === 2147483648.

edit3: opened #32420 to fix that.

bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Mar 22, 2020
`actual` is the first argument, `expected` the second, but the test
flipped them around and was producing confusing assertion messages
as a result.

Refs: nodejs#32408 (comment)
@bnoordhuis
Copy link
Member Author

EINVAL - I'm reasonably sure utimensat() doesn't allow pre-epoch dates

I might be mistaken about that because the soon-to-be-added libuv test fs_utime_round from libuv/libuv#2747 does pretty much the same thing yet passes... I'll investigate more.

addaleax pushed a commit that referenced this pull request Apr 2, 2020
`actual` is the first argument, `expected` the second, but the test
flipped them around and was producing confusing assertion messages
as a result.

Refs: #32408 (comment)

PR-URL: #32420
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
BethGriggs pushed a commit that referenced this pull request Apr 7, 2020
`actual` is the first argument, `expected` the second, but the test
flipped them around and was producing confusing assertion messages
as a result.

Refs: #32408 (comment)

PR-URL: #32420
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this pull request Apr 12, 2020
`actual` is the first argument, `expected` the second, but the test
flipped them around and was producing confusing assertion messages
as a result.

Refs: #32408 (comment)

PR-URL: #32420
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this pull request Apr 22, 2020
`actual` is the first argument, `expected` the second, but the test
flipped them around and was producing confusing assertion messages
as a result.

Refs: #32408 (comment)

PR-URL: #32420
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:18
@bnoordhuis
Copy link
Member Author

Superseded by #43714.

@bnoordhuis bnoordhuis closed this Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.Stat fails on pre-epoch mtime (<1970-01-01T00:00:00Z)
2 participants