writeFile has a Year 2038 bug on Windows
(1) By anonymous on 2025-01-03 09:39:41 [source]
Int32x32To64
macro internally truncates the arguments to int32, while time_t
is 64-bit on most/all modern platforms. Therefore, usage of this macro creates a Year 2038 bug.
I detailed this issue a while ago in a writeup, and spotted the same issue in this repository when updating the list of affected repositories: https://cookieplmonster.github.io/2022/02/17/year-2038-problem/
In SQLite, this macro is present in fileio.c
in the writeFile
function:
https://github.com/sqlite/sqlite/blob/04364cb3cc108a044a0d9dc7162f4d550adb2f99/ext/misc/fileio.c#L440
The correct fix would be to simply multiply without the macro here, and ensure expansion to an int64 by using 10000000LL
.
(2) By anonymous on 2025-01-03 14:34:58 in reply to 1 [link] [source]
Thanks for a quick fix! One more nitpick, though - the current code does not use an LL suffix on the 10000000 constant, so if SQLite is present on any platform that uses this code path and has a 32-bit time_t
, the result won't be correctly expanded to 64-bit. If time_t
is 64-bit everywhere, though, then it will work fine.
(3) By Richard Hipp (drh) on 2025-01-03 18:49:30 in reply to 2 [link] [source]
I believe the "mtime" variable in question is declared as "sqlite3_int64" which is always 64-bit. The file in question does declare any variables of type "time_t".
(4) By anonymous on 2025-01-03 22:32:37 in reply to 3 [link] [source]
You're right and I missed it - in this case, everything is in order. Thank you!