Repository navigation
Fix undefined behaviour in DateTimeBestEffort parsing - #100948
Conversation
1. Follow same pattern which already existed. 2. Consistently use "if constexpr (strict)"
|
@Avogar fyi |
|
Workflow [PR], commit [12d6c92] Summary: ❌
AI ReviewSummaryThis PR fixes undefined behavior in ClickHouse Rules
Final Verdict
|
|
Duplicate of #100368? |
Yep. I throw a |
Test that parsing datetime strings with many fractional digits (more than `Int64::digits10 = 18`) does not cause signed integer overflow in `readDecimalNumber`. Covers 10-digit and 9-digit unix timestamps with fractional parts, and regular datetime strings. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Actually, I think my Claude wrote better test :) |
…comment `readDigits` reads up to `UInt64::digits10 = 19` digits into its buffer, so a 19-digit fractional tail is consumed and truncated to 18 (silently dropped), while a 20-digit tail leaves the 20th digit in the stream and causes a parse error. Add the 19-digit case to lock in the expected truncation behavior and update the comment to reflect the actual boundary. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The previous test used fractional values that fit in Int64 even without the cap, so the bugfix validator (which runs the test against master) correctly reported "failed to reproduce the bug". Use 19 nines as the fractional part: without the cap, `readDecimalNumber` processes chunks 4+4+4+4+3 and the final step `9999999999999999 * 1000` overflows Int64. With the fix the count is capped to 18 (chunks 4+4+4+4+2) and no overflow occurs. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
#100965 is fix for test failure |
|
Fix for flaky test #100988 |
|
@alexey-milovidov I have no idea what to do with that CI failure. Everything else looks green. |
|
We recently enabled server-side AST fuzzer in Stress tests, it might be related. |
Sigh. Wasn't that feature removed and that test shouldn't exist? Or it's some stale caches? |
|
@alexey-milovidov I have no idea what else I can do to land it. |
483148b
|
Hi — this PR may need backporting to release branches Why: This fixes UB (signed integer overflow) producing wrong results in parseDateTimeBestEffort, which is core DateTime parsing code present in all stable releases. Users providing datetime strings with 19+ fractional digits get silently wrong results. If this should be backported, consider adding |
Backport #100948 to 26.3: Fix undefined behaviour in DateTimeBestEffort parsing
Backport #100948 to 26.2: Fix undefined behaviour in DateTimeBestEffort parsing
Backport #100948 to 26.1: Fix undefined behaviour in DateTimeBestEffort parsing
Backport #100948 to 25.8: Fix undefined behaviour in DateTimeBestEffort parsing
parseDateTimeBestEffort accumulated fractional-second digits into an Int64 without capping the count, causing signed integer overflow.
Fix: cap fractional digit count to std::numeric_limits::digits10 at all three call sites. Also consistently use if constexpr (strict) since strict is a template parameter.
Related CI failure: https://github.com/ClickHouse/ClickHouse/actions/runs/23661784718/job/68936469304?pr=100435#step:4:11003
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix undefined behavior (signed integer overflow) in parseDateTimeBestEffort when parsing datetime strings with more than 18 fractional-second digits.
Version info
26.4.1.53026.3.4.6,26.2.8.9,26.1.8.16,25.8.22.22