Repository navigation
Fix date functions returning garbage for unrepresentable timestamps - #11760
Conversation
Covers timefmt and the eight date extraction/rounding functions with timestamps that fit in time_t but overflow struct tm's year, and with values outside time_t (2^63, inf, nan), both shard-side and coordinator-side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hour, day, dayofmonth, dayofweek, dayofyear, year, month and monthofyear ignored gmtime_r failure and returned values built from the partially written struct tm. All nine date functions, timefmt included, also cast the double argument to time_t without a range check, which is undefined behavior for NaN, infinity and values >= 2^63. Convert through a helper that rejects values outside time_t before the cast and fails when gmtime_r fails. Such inputs now yield null, the existing result for invalid input. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9e224d8ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| timestamps = ('67768036191676800', '1000000000000000000', | ||
| '9223372036854775808', '"inf"', '"nan"') |
There was a problem hiding this comment.
Cover the finite lower time_t boundary
The new helper adds both upper- and lower-bound rejection before converting the double to time_t, but every finite out-of-range value here is positive; only timefmt can reach the new lower-bound path because the other functions already reject all negative inputs. Add a representable double below INT64_MIN, such as -9223372036854777856, and assert that timefmt returns null, so the newly added UB-prevention behavior for finite negative overflow is covered.
AGENTS.md reference: AGENTS.md:L22-L22
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11760 +/- ##
==========================================
- Coverage 84.13% 83.50% -0.64%
==========================================
Files 642 668 +26
Lines 85156 86183 +1027
Branches 39311 40368 +1057
==========================================
+ Hits 71644 71963 +319
- Misses 13149 13849 +700
- Partials 363 371 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|



Describe the changes in the pull request
hour,day,dayofmonth,dayofweek,dayofyear,year,monthandmonthofyearignore a failedgmtime_r, so a timestamp whose year doesn't fit in anint(≥ ~6.8e16) returns a meaningless number:year(67768036191676800)returns-2147481748. All nine date functions,timefmtincluded, also cast the argument totime_twith no range check, which is undefined behavior fornan,infand values ≥ 2^63. Those values reach the functions as literals or as numeric strings such as"nan".timefmtand fractional seconds.APPLYandFILTERexpressions inFT.AGGREGATEandFT.HYBRIDno longer compute results, filters or groups from garbage dates.Which additional issues this PR fixes
Main objects this PR modified
src/aggregate/functions/date.c: a newtimestampToTm()helper rejects out-of-range values, including NaN, before the cast and checks the result ofgmtime_r. All nine date functions use it. A_Static_assertmakes a 64-bittime_ta build requirement.tests/pytests/test.py:testDateFunctionsRejectUnrepresentableTimestampsruns every date function on five unrepresentable inputs, both shard-side and on the coordinator (afterGROUPBY), and checks that valid timestamps keep their results.Mark if applicable
Release Notes
If a release note is required (bug fix / new feature / enhancement), describe the user impact of this PR in the title.
🤖 Generated with Claude Code