Skip to content

Commit

Permalink
Fix a Y2038 bug by replacing Int32x32To64 with regular multiplication
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CookiePLMonster committed Jan 3, 2025
1 parent 5beaf27 commit d7e84c6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libsql-ffi/bundled/SQLite3MultipleCiphers/src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static int writeFile(

GetSystemTime(&currentTime);
SystemTimeToFileTime(&currentTime, &lastAccess);
intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
intervals = (mtime * 10000000LL) + 116444736000000000LL;
lastWrite.dwLowDateTime = (DWORD)intervals;
lastWrite.dwHighDateTime = intervals >> 32;
zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
Expand Down
2 changes: 1 addition & 1 deletion libsql-ffi/bundled/SQLite3MultipleCiphers/src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -7514,7 +7514,7 @@ static int writeFile(

GetSystemTime(&currentTime);
SystemTimeToFileTime(&currentTime, &lastAccess);
intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
intervals = (mtime * 10000000LL) + 116444736000000000LL;
lastWrite.dwLowDateTime = (DWORD)intervals;
lastWrite.dwHighDateTime = intervals >> 32;
zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
Expand Down
2 changes: 1 addition & 1 deletion libsql-sqlite3/ext/misc/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static int writeFile(

GetSystemTime(&currentTime);
SystemTimeToFileTime(&currentTime, &lastAccess);
intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
intervals = (mtime * 10000000LL) + 116444736000000000LL;
lastWrite.dwLowDateTime = (DWORD)intervals;
lastWrite.dwHighDateTime = intervals >> 32;
zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
Expand Down

0 comments on commit d7e84c6

Please sign in to comment.