Skip to content

Fix date functions returning garbage for unrepresentable timestamps - #11760

Merged
eyalrund merged 2 commits into
masterfrom
eyalrund-fix-date-functions-timestamps
Oct 5, 2026
Merged

eyalrund merged 2 commits into
masterfrom
eyalrund-fix-date-functions-timestamps

Conversation

@eyalrund

@eyalrund eyalrund commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

  1. Current: hour, day, dayofmonth, dayofweek, dayofyear, year, month and monthofyear ignore a failed gmtime_r, so a timestamp whose year doesn't fit in an int (≥ ~6.8e16) returns a meaningless number: year(67768036191676800) returns -2147481748. All nine date functions, timefmt included, also cast the argument to time_t with no range check, which is undefined behavior for nan, inf and values ≥ 2^63. Those values reach the functions as literals or as numeric strings such as "nan".
  2. Change: these inputs now return null, which is what the date functions already return for non-numeric input. Valid timestamps are unaffected, including negative input to timefmt and fractional seconds.
  3. Outcome: APPLY and FILTER expressions in FT.AGGREGATE and FT.HYBRID no longer compute results, filters or groups from garbage dates.

Which additional issues this PR fixes

  1. N/A

Main objects this PR modified

  1. src/aggregate/functions/date.c: a new timestampToTm() helper rejects out-of-range values, including NaN, before the cast and checks the result of gmtime_r. All nine date functions use it. A _Static_assert makes a 64-bit time_t a build requirement.
  2. tests/pytests/test.py: testDateFunctionsRejectUnrepresentableTimestamps runs every date function on five unrepresentable inputs, both shard-side and on the coordinator (after GROUPBY), and checks that valid timestamps keep their results.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require 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

eyalrund and others added 2 commits October 4, 2026 14:53
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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T13:38:34.874186Z d9e224d PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the size:S label Oct 4, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/pytests/test.py
Comment on lines +3424 to +3425
timestamps = ('67768036191676800', '1000000000000000000',
'9223372036854775808', '"inf"', '"nan"')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@eyalrund
eyalrund requested a review from GuyAv46 October 4, 2026 13:40
@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.50%. Comparing base (8c58d4f) to head (d9e224d).
⚠️ Report is 4 commits behind head on master.

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     
Flag Coverage Δ
flow 84.60% <100.00%> (-0.02%) ⬇️
unit 58.74% <0.00%> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Oct 4, 2026

Copy link
Copy Markdown

@eyalrund
eyalrund added this pull request to the merge queue Oct 5, 2026
Merged via the queue into master with commit df67d06 Oct 5, 2026
61 checks passed
@eyalrund
eyalrund deleted the eyalrund-fix-date-functions-timestamps branch October 5, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants