Skip to content

Fix signed Int64 overflow when computing fraction in roundTimeConstant - #129979

Open
zaidrain06 wants to merge 2 commits into
ClickHouse:masterfrom
zaidrain06:fix/issue-129976-qcc-fraction-overflow
Open

zaidrain06 wants to merge 2 commits into
ClickHouse:masterfrom
zaidrain06:fix/issue-129976-qcc-fraction-overflow

Conversation

@zaidrain06

@zaidrain06 zaidrain06 commented Nov 7, 2026 •

Copy link
Copy Markdown

Closes: #129976
Related: #129017

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix signed Int64 overflow when computing fraction in roundTimeConstant (QueryConditionCacheTimeConditions.cpp) for DateTime64(4..9) values near INT64_MIN.

Details

In roundTimeConstant (src/Interpreters/Cache/QueryConditionCacheTimeConditions.cpp:179), whole_seconds * multiplier overflows signed Int64 when ticks is within one second above INT64_MIN (e.g. INT64_MIN + 1) and scale is in 4..9, because floor(ticks / multiplier) is -9223372037 for scale 9 (-9223372037 * 10^9 < INT64_MIN), which passes the max_reasonable_seconds (1e15) check at line 145.

Computing fraction directly via ticks % multiplier (and adding multiplier when negative) avoids the intermediate whole_seconds * multiplier product and eliminates the UBSan signed integer overflow. Added unit test coverage DateTime64NearInt64MinDoesNotOverflowFraction in src/Interpreters/tests/gtest_query_condition_cache_time_conditions.cpp covering scales 4, 6, and 9 for both Weaken and Strengthen.


Workflow [PR]
Sync PR [sync-upstream/pr/129979]

@cla-assistant

cla-assistant Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 7, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh clickhouse-gh Bot added comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. external Author is not a member of the ClickHouse organization labels Nov 7, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f7aee2e]

Summary: ✅

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) SKIPPED CIDB timeout in test selection, rerun to test

AI Review

Summary

The PR fixes signed Int64 overflow in roundTimeConstant for extreme negative DateTime64 constants by computing the fractional remainder without multiplication. It adds regression coverage for scales 4, 6, and 9 in both rounding directions. The earlier finding about the Strengthen expectation is fixed in f7aee2e35f5769da57ac87f70ddaba0b9067c9ac, and its bot-authored thread has been resolved. No outstanding findings.

Missing context / blind spots
  • ⚠️ Tests were not run locally because this checkout has no configured build. The current Unit tests (asan_ubsan) CI report is pending; its result will provide sanitizer execution evidence for the regression test.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f7aee2e35 with master 52d3d52bb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. and removed comp-filesystem-cache Filesystem cache for remote/object storage, page cache, and read caching infrastructure. labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fraction product still overflows for DateTime64(4..9) near INT64_MIN

2 participants