os: fix Chtimes timestamp overflow for dates outside 1677-2262#78125
os: fix Chtimes timestamp overflow for dates outside 1677-2262#78125zheliu2 wants to merge 2 commits intogolang:masterfrom
Conversation
os.Chtimes used time.UnixNano() to convert timestamps to syscall timespecs, which overflows int64 for dates before 1677 or after 2262. Add syscall.SecNsecToTimespec that takes separate seconds and nanoseconds values, avoiding the need to compute seconds * 1e9. Use this in os.Chtimes instead of NsecToTimespec(t.UnixNano()). Also fix the same overflow in the Windows codepath, both in syscall.UtimesNano and os.chtimesat, by computing FILETIME ticks from seconds and nanoseconds separately. Fixes golang#75542
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: 7d5275b) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/754663. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/754663. |
|
Message from Ian Lance Taylor: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/754663. |
os.Chtimes used time.Time.UnixNano() to convert timestamps to syscall
timespecs, which overflows int64 for dates before ~1677 or after ~2262.
This corrupts timestamps on filesystems that support wider date ranges
(ext4, NTFS, APFS, etc.).
Changes:
seconds and nanoseconds, avoiding the seconds * 1e9 overflow inherent
in NsecToTimespec
os.chtimesUtimes instead of NsecToTimespec(t.UnixNano())
os.chtimesat) by computing FILETIME ticks from seconds and
nanoseconds separately
Fixes #75542