Skip to content

Read dates after 2038 correctly on 32-bit builds - #2002

Merged
xroche merged 5 commits into
masterfrom
time-2038
Oct 21, 2026
Merged

xroche merged 5 commits into
masterfrom
time-2038

Conversation

@xroche

@xroche xroche commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

On a 32-bit time_t, timegm() fails after 2038-01-19, so mirrored files kept their download time and Retry-After dates were ignored. Every date now goes through hts_utc_seconds(), the 64-bit day count from #1982, and a file time past time_t is clipped to its last second. On 32-bit builds, a date before 1901 now stamps the file at 1901-12-13 and gives a Retry-After of 0, as on 64-bit.

xroche and others added 4 commits October 21, 2026 14:33
timegm() returns -1 for any date past 2038-01-19T03:14:07Z when time_t is
32 bits (Debian i386, armhf before t64, Win32 with _USE_32BIT_TIME_T), so a
mirrored file kept its download time, a Retry-After date was ignored, and
proxytrack listed such files as 1969.

Move the 64-bit day count #1982 added for cookie Expires into htsdate.c as
hts_utc_seconds(), shared with proxytrack, and convert every timegm() site
through it. hts_time_clip() bounds the result where a time_t is needed: a
file time stamps the last second a 32-bit time_t holds, never 1901. The FTP
resume check refuses a clipped date, because two clipped dates would compare
equal. The lock file's START= line is printed in 64 bits.

Test 659 checks dates on both sides of 2038, 2106 and 9999 through the date
parser, Retry-After and a file mtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Review round 1 on #2002. set_filetime and proxytrack's ARC timestamp now
share hts_tm_filetime(), and the FTP MDTM guard is hts_time_exact(), tested
in st_y2038. New rows: 1900 and 2100 leap days, years 0 and -1, a
Retry-After date equal to the reference, and an epoch date that must leave
a file's time alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche enabled auto-merge (squash) October 21, 2026 13:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit 6a0aed8 into master Oct 21, 2026
38 checks passed
@xroche
xroche deleted the time-2038 branch October 21, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant