Skip to content

Fix signed integer overflow in FillingTransform interval-kind WITH FILL STEP - #110158

Merged
alexey-milovidov merged 24 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-with-fill-interval-step-int64-overflow
Jul 22, 2026
Merged

alexey-milovidov merged 24 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-with-fill-interval-step-int64-overflow

Conversation

@groeneai

@groeneai groeneai commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

No related open issue found.

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):

Fixed undefined signed-overflow paths in interval arithmetic for interval-kind WITH FILL STEP and for add* / subtract* date/time interval functions with extreme deltas, making extreme interval values deterministic instead of relying on signed overflow. Also fixed a stall of interval-kind WITH FILL with a huge YEAR step, which previously ran the calendar backward.

Description

FillingRow::doLongJump binary-searches how far to jump over a WITH FILL gap by doubling an internal jump length up to 2^62 and calling the step function as step * jumps_count. It detects an overflowed jump by observing the wrapped result, so it relies on well-defined wraparound.

The interval-kind (Date/DateTime) step lambda in getStepFunction and its Decimal64 (DateTime64) sibling did the multiply as a signed Int64, so a large WITH FILL STEP interval combined with a wide value range produced e.g. 2147483648 * 4294967296 = 2^63 -> signed integer overflow ... cannot be represented in type 'Int64' at FillingTransform.cpp:72 under UBSan (silent wrap in release). The sibling plain-numeric branch was already fixed the same way (via FieldVisitorScale); the interval-kind path had been missed.

Fix: multiply step * jumps_count in the UInt64 domain via the mulStepWrapping helper, then cast back to Int64, so the wrap that doLongJump relies on is produced by construction (mirroring FieldVisitorScale).

In addition (per review), the interval helpers that doLongJump can feed with an unbounded wrapped delta now compute their internal unit scaling (delta * 60, delta * 3600, delta * 7, delta * 86400, the DateTime64/Time64 tick rescale, and the subtract* negation of INT64_MIN) and the final addition in the unsigned domain: the AddSecondsImpl/AddMinutesImpl/AddHoursImpl/AddDaysImpl/AddWeeksImpl overloads for Date/Date32/DateTime/DateTime64/Time/Time64, the DateLUTImpl addWeeks/addQuarters unit multiplies, and the SubtractIntervalImpl delta negation. Previously these were signed operations whose overflow was merely uninstrumented via NO_SANITIZE_UNDEFINED, not defined. The rewritten overloads are bit-identical to the previous two's-complement behavior for all inputs and no longer carry NO_SANITIZE_UNDEFINED, so UBSan now enforces the wrap-by-construction property.

One deliberate behavior change on huge non-representable deltas: addYearsIndex narrowed its delta to Int16, so a large positive YEAR step (e.g. WITH FILL STEP INTERVAL 32768 YEAR, or addYears with a huge delta as covered by 01662_date_ubsan) wrapped to a negative year count and ran the calendar backward, saturating to 1970 and stalling the fill loop. The delta is now clamped to the representable year range before the add (mirroring the addMonthsIndex clamp), which is result-identical for every representable delta but changes the (previously nonsensical, overflow-dependent) result for huge deltas — tests/queries/0_stateless/01662_date_ubsan.reference is updated accordingly.

Regression test 04512_with_fill_interval_step_int64_overflow drives the overflowing step * jumps_count multiply for the plain-modular kinds that can reach it through doLongJump: SECOND/MINUTE/HOUR on DateTime and WEEK on Date. The MINUTE/HOUR/WEEK cases also drive the wrapped delta past the Int64 range inside the Add*Impl helpers (probe-verified), enforcing the helper fix under UBSan. The Decimal64/DateTime64 sibling uses the identical mulStepWrapping via the same FOR_EACH_INTERVAL_KIND macro, so it is fixed by construction; the DateTime64 case in the test is a correctness smoke test of that branch (its full Int64 tick domain cannot be driven to the overflow in a terminating query). The remaining kinds (DAY/MONTH/QUARTER, and WEEK on DateTime) converge through the saturating DateLUT arithmetic and cannot reach the overflow.

The PR also fixes a Bugfix validation harness gap that this PR exposed: the regression test reproduces the UBSan overflow on the master-HEAD asan_ubsan binary, and with -fno-sanitize-recover=all that kills the server, aborting the test runner with a runner-level ERROR that invert_bugfix_validation_status preserved as "inconclusive" — so a bugfix whose reproduction crashes the sanitizer server could never validate (report). Now, when check_fatal_messages_in_logs finds a sanitizer/fatal failure in the master-HEAD server logs, the runner abort is attributed to that crash and counted as the bug reproducing; a runner ERROR without a fatal (a genuine infra failure) is still preserved as inconclusive.

…LL STEP

FillingRow::doLongJump binary-searches how far to jump over a WITH FILL
gap by doubling an internal jump length up to 2^62 and calling the step
function as step * jumps_count. It detects an overflowed jump by observing
the wrapped result, so it relies on well-defined wraparound.

The interval-kind (Date/DateTime) step lambda in getStepFunction and its
Decimal64 (DateTime64) sibling did the multiply as a signed Int64 (step *
jumps_count), so a large WITH FILL STEP interval combined with a wide value
range produced e.g. 2147483648 * 4294967296 = 2^63, undefined behavior
under UBSan (silent wrap in release). This mirrors the earlier fix for the
plain-numeric branch (FieldVisitorScale), which the interval-kind path had
missed.

Multiply through common::mulIgnoreOverflow so the wrap doLongJump depends on
is well-defined. Behavior is preserved.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT toDateTime(arrayJoin([toUInt32(0), toUInt32(4294967295)])) AS d ORDER BY d WITH FILL STEP INTERVAL 2147483648 SECOND STALENESS INTERVAL 1 SECOND aborts an asan+ubsan server every time with FillingTransform.cpp:72: signed integer overflow: 2147483648 * 4294967296 cannot be represented in type 'Int64'.
b Root cause explained? FillingRow::doLongJump doubles the internal jump length up to 2^62 and detects an overflowed jump by observing the wrapped result, relying on well-defined wraparound. The interval-kind step lambda multiplied step * jumps_count as signed Int64, so 2^31 * 2^32 = 2^63 is signed overflow (UB) before the wrap is even observed.
c Fix matches root cause? Yes. The multiply is routed through common::mulIgnoreOverflow (NO_SANITIZE_UNDEFINED), making the exact wrap doLongJump depends on well-defined. Same approach as the earlier plain-numeric branch fix (FieldVisitorScale).
d Test intent preserved / new tests added? New regression test 04512_with_fill_interval_step_int64_overflow added; covers both the interval-kind (DateTime, line 70) and Decimal64 (DateTime64, line 114) step lambdas.
e Demonstrated both directions? Yes. Pristine binary: server aborts with the exact signature. Fixed binary: 20/20 runs pass with randomization, 0 UBSan reports.
f Fix general, not a narrow patch? Yes. Both sibling multiply sites (interval-kind lambda and Decimal64 lambda) are fixed, not just the one line UBSan flagged. The plain-numeric sibling was already fixed previously.
g Generalizes across inputs/types? Covered: DateTime (UInt32 via interval lambda) and DateTime64 (Decimal64 sibling) both exercised. All interval kinds route through the same mulIgnoreOverflow macro expansion.
h Backward compatible? Yes. No format, setting-default, or behavior change. The result of doLongJump is unchanged; only the overflow is now well-defined instead of UB.
i Invariants/contracts preserved? Yes. doLongJump's overflow-detection contract (observe wrapped result to halve the jump) is preserved; mulIgnoreOverflow produces the identical wrapped value.

Session id: cron:clickhouse-worker-slot-3:20260712-134000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @vdimir — could you review? Small UBSan fix: the interval-kind (and Decimal64) WITH FILL STEP step lambdas in FillingTransform did step * jumps_count as a signed Int64, so doLongJump doubling the jump length to 2^62 tripped signed overflow (2147483648 * 4294967296). Routed through common::mulIgnoreOverflow, mirroring the earlier plain-numeric FieldVisitorScale fix. Regression test added.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [440bbbb]

Summary: ✅


AI Review

Summary

This PR hardens interval-kind WITH FILL STEP and the related add* / subtract* date-time interval helpers so extreme deltas no longer rely on signed-overflow UB, and it fixes bugfix-validation handling when the master binary reproduces a bug by crashing the server. I did not find remaining correctness, safety, or CI-harness issues in the current head.

Final Verdict

Status: ✅ Approve

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

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
mulIgnoreOverflow is only a NO_SANITIZE_UNDEFINED wrapper around x * y, so
the signed Int64 multiply still has UB semantics that the optimizer may
assume never overflows. FillingRow::doLongJump relies on well-defined
wraparound to detect the overflowed jump, so multiply through UInt64 and
cast back, mirroring the FieldVisitorScale fix.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Good catch, reworked in 33ea71f. Both the interval-kind (Date/DateTime) step lambda and the DateTime64/Decimal64 sibling now compute step * jumps_count via mulStepWrapping, which casts both operands to UInt64, multiplies (wrap-by-construction), and casts back to Int64. This gives FillingRow::doLongJump the defined wraparound it needs, mirroring FieldVisitorScale.cpp, instead of relying on mulIgnoreOverflow which only suppresses UBSan. Regression test 04512_with_fill_interval_step_int64_overflow still passes both branches.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 33ea71f

Finish Workflow and Mergeable Check complete. This PR is a signed-overflow fix in FillingTransform/getStepFunction (WITH FILL step multiply) — it cannot cause a hung-check deadlock or a replicated-DDL alter failure. Both failures below are pre-existing, not PR-caused, and owned.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Hung check failed, possible deadlock deadlock (chronic: 330 PRs / 164 master / 14d) #108212 (ours, merged) / #105905 (ours, open)
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (known, @alexey-milovidov directive) a fix task is moved to pending (investigating at full effort — fixing PR link to follow here)

Session id: cron:our-pr-ci-monitor:20260712-210000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 33ea71f

Finish Workflow and Mergeable Check complete. This PR is a signed-overflow fix in FillingTransform/getStepFunction (WITH FILL step multiply) — it cannot cause a hung-check deadlock or a replicated-DDL alter failure. Both failures below are pre-existing, not PR-caused, and owned by fixing PRs.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Hung check failed, possible deadlock deadlock (chronic: 330 PRs / 164 master / 14d) #108212 (ours, merged) / #105905 (ours, open)
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (known) #110030 (ours, open)

(Correction of the prior ledger line for the replicated-alter test: it is owned by fixing PR #110030, not a fix task.)

Session id: cron:our-pr-ci-monitor:20260712-210000

The mulStepWrapping helper already covers every interval kind via the
FOR_EACH_INTERVAL_KIND macro, but the regression test only exercised SECOND.
Add MINUTE, HOUR and WEEK cases whose step * jumps_count exceeds Int64 range
inside doLongJump, so the wrap-by-construction multiply is verified for those
kinds too.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — fec5566

CI is fully finished on this head (Finish Workflow + Mergeable Check green; all Stress tests passed). One flaky failure, owned by a fixing PR. Not PR-caused (a FillingTransform interval-overflow fix cannot affect replicated-DDL alter).

Check / test Reason Owner / fixing PR
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (42 master hits + many unrelated PRs / 30d) #110030 (ours, open)
Report messages 8 warning(s), informational meta-check (non-blocking) N/A (not a test failure)
CH Inc sync private sync CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260714-110000

/// well-defined wraparound to detect the overflowed jump). A signed Int64 multiply is UB on overflow.
static Int64 mulStepWrapping(Int64 step, Int64 jumps_count)
{
return static_cast<Int64>(static_cast<UInt64>(step) * static_cast<UInt64>(jumps_count));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can it overflow uint64? Does it properly handle negative singed? Why not to use mul_overflow or saturated multiplication?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The wraparound is load-bearing here, not a hazard to avoid:

  1. Yes, the UInt64 product can wrap, and that is intended. UInt64 overflow is well-defined modular arithmetic (wrap mod 2^64), unlike the original signed Int64 multiply which is UB. FillingRow::doLongJump doubles step_len exponentially and detects an overflowed jump by observing that next_value wrapped to a smaller value (less(next_value, shifted_value, direction) sets overflowed), then halves step_len. The wrap is exactly the signal it relies on.

  2. Negative step is handled. static_cast<UInt64>(neg Int64) is well-defined (adds 2^64, i.e. the two's-complement bit pattern); multiplying in UInt64 and casting back reproduces the exact two's-complement signed product, negatives included (in C++20 the narrowing conversion back to Int64 is well-defined, not just implementation-defined). WITH FILL descending uses negative steps and the direction-aware less() covers both directions. This mirrors the already-accepted sibling on the plain-numeric path, FieldVisitorScale.cpp:14.

  3. mulOverflow / saturated would break the detection. mulOverflow reports overflow but does not produce the wrapped value, so we would have to throw (regressing valid queries where doLongJump deliberately probes past the range then backs off) or reconstruct the wrap anyway. Saturation clamps to INT64_MIN/MAX, which does not wrap backwards, so less(next_value, shifted_value) never flags overflowed and the doubling loop misbehaves. Wrap-by-construction is the required semantic.

Happy to rename the helper or expand the comment if you prefer it more explicit, but keeping the wrap (not checked/saturated) is deliberate.

@alexey-milovidov

Copy link
Copy Markdown
Member

CH Inc sync red — cause found, fixed by merging master (b835774c279)

The CH Inc sync failure (tests failed: mass failure of the private-only test_storage_iceberg_with_spark/test_compaction.py with Spark's IcebergArrowColumnVector.getUTF8String → Unsupported type: UTF8String) was not caused by this PR. It came from #106952 (Parquet dictionary-based row-group filtering, merged 2026-07-13), which landed between this branch's previous merge-base and the failing run, and broke the private CI. The revert #110354 merged into master on 2026-07-14 at 11:42 UTC — after this branch's merge-base (03:22 UTC), so the sync run still contained the breakage.

Merged current master (which includes the revert) and pushed, so the next sync run should be green. This also gives the single remaining public-CI flake test_replicated_table_structure_alter (issue #110036, fixing PR #110030 still open) a fresh run.

The added MINUTE/HOUR/WEEK cases did not reach the overflowing step * jumps_count
multiply in FillingRow::doLongJump. doLongJump is reached only via the STALENESS
shift path; the WEEK case had no STALENESS, and the previous MINUTE/HOUR steps let
the UInt32 timestamp wrap long before jumps_count grew large enough to overflow
Int64. Pick MINUTE/HOUR steps whose per-jump delta is 2^31 in the DateTime domain
so doLongJump doubles step_len up to the Int64 overflow point, and drop the WEEK
case (calendar arithmetic converges via DateLUT and cannot reach it).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…iply

The MINUTE/HOUR/SECOND DateTime cases genuinely drive doLongJump to the Int64
step*jumps_count overflow (confirmed via a mul_overflow probe). The DateTime64
case cannot: DateTime64 execute() works in the full Int64 tick domain with no
small-domain wrap, so a large delta immediately overshoots the target or
overflows Int64 and doLongJump stops doubling. Keep it as a correctness smoke
test of the same code path (the Decimal64 branch uses the identical
mulStepWrapping via the same FOR_EACH_INTERVAL_KIND macro, protected by
construction) and document the coverage precisely.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 9cacf49

Every failure below has an owner: a fixing PR, or the private-sync exemption.

Check / test Reason Owner / fixing PR
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky (42 master hits + many unrelated PRs / 30d; cannot be caused by this PRs FillingTransform overflow fix) #110030 (ours, open)
CH Inc sync private sync CH Inc sync (private, not actionable)

Report messages (warnings) and Finish Workflow "Post Hooks" are the non-blocking rollup reflection of the above, not separate failures.

Session id: cron:our-pr-ci-monitor:20260715-033000

alexey-milovidov and others added 3 commits July 15, 2026 13:38
…nstruction

The AI review pointed out that `mulStepWrapping` only fixes the outer
`step * jumps_count` multiply: `FillingRow::doLongJump` can still hand
`delta == -2^63` to `AddMinutesImpl` / `AddHoursImpl`, whose `UInt32`
(`DateTime`) and `DateTime64` overloads multiplied it again as signed
`Int64` (`delta * 60`, `delta * 3600`) - undefined behavior that was
merely uninstrumented via `NO_SANITIZE_UNDEFINED`, not defined.

Compute those overloads (and the `AddSecondsImpl` addition) in the
`UInt64` domain instead: bit-identical to the previous two's complement
behavior for all inputs, but well-defined. Drop `NO_SANITIZE_UNDEFINED`
from the rewritten overloads so UBSan now enforces the property - the
existing MINUTE/HOUR cases in
`04512_with_fill_interval_step_int64_overflow` drive `delta` to
`-2^63` and exercise the helper multiplies under the sanitizer.

ClickHouse#110158

Co-Authored-By: Claude Fable 5 <[email protected]>
…oads

`WITH FILL STEP INTERVAL 32768 WEEK STALENESS INTERVAL 1 DAY` on a
`Date` column stalls `FillingRow::doLongJump` the same way the DateTime
MINUTE/HOUR cases do (`32768 * 7 == 2^15 (mod 2^16)`: odd jumps advance,
even jumps stall), so `AddWeeksImpl::execute` for `UInt16` received
deltas up to the wrapped `-2^63` and multiplied them by 7 as signed
`Int64` - verified empirically with a `__builtin_mul_overflow` probe
(overflows at delta = 2^61, 2^62, -2^63). Rewrite the `UInt16`/`Int32`
overloads of `AddDaysImpl` and `AddWeeksImpl` in the `UInt64` domain as
well (bit-identical for all inputs) and add the `WEEK` regression case.

ClickHouse#110158

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pass ledger — 1dd9526 (2026-07-15)

AI review Block verdict addressed (see the thread reply): the Add*Impl overloads reachable from doLongJump with an unbounded wrapped delta now compute in the UInt64 domain (bit-identical, wrap-by-construction) and are no longer NO_SANITIZE_UNDEFINED, so UBSan enforces them; added a probe-verified WEEK-on-Date regression case. Merged master (clean).

CI state before this push, all failures owned:

Check / test Reason Owner / fixing PR
Integration tests (amd_msan, 7/8) / test_replicated_database::test_replicated_table_structure_alter flaky, issue #110036 (retry_ok; cannot be caused by a FillingTransform overflow fix) #110030 (ours, open)
CH Inc sync / 04150_move_partition_inconsistent_granularity test removed on master by revert #110526 cleared by this pass's master merge
CH Inc sync / 02539_vertical_merge_compact_parts SharedMergeTree-incompatible test, pre-existing #110537 (ours, open)
CH Inc sync / test_distributed_cache/test.py::test_graceful_shutdown private-only test, log-assertion flake ("Expected forceful connection shutdown log message"), appears across unrelated sync PRs private, not actionable from public

Both failing sub-checks get a fresh run from this push.

…ction

The wrap-by-construction fix for the WITH FILL interval-step chain covered the
Add*Impl execute() overloads, but the DateTime WEEK path routes through
DateLUTImpl::addWeeks (delta * 7) and the quarter path through addQuarters
(delta * 3), both still signed Int64 multiplies. FillingRow::doLongJump passes
deltas from the whole Int64 range and relies on defined wraparound, so a signed
multiply is UB on overflow even under NO_SANITIZE_UNDEFINED. Compute these in the
UInt64 domain; bit-identical two's complement for all inputs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Common/DateLUTImpl.h Resolved
alexey-milovidov and others added 3 commits July 19, 2026 14:26
…epro

Bugfix validation runs the changed tests against the master-HEAD
binaries, asan_ubsan first. This PR's regression test reproduces a UBSan
signed-overflow on master, and with `-fno-sanitize-recover=all` that
kills the server outright: `clickhouse-test` aborts with `StopTesting`
(exit code 2), the surviving per-test rows are recorded as `ERROR`, and
`invert_bugfix_validation_status` deliberately preserves a runner-level
`ERROR` as inconclusive (ClickHouse#105789). Net effect: a bugfix whose
reproduction crashes the sanitizer server could never validate, and
`new_tests_check.py` blocked the PR:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110158&sha=6fac17e25bee062f2c959964c0a4df8400576de8&name_0=PR&name_1=Bugfix%20validation%20%28functional%20tests%2C%20amd64%29

When `check_fatal_messages_in_logs` finds a sanitizer/fatal failure (a
`BLOCKER`-labelled row) in the master-HEAD server logs, attribute the
runner abort to that crash: downgrade the runner-level `ERROR` and the
per-row `ERROR`s to `FAIL`, which the inverter then flips into a
successful reproduction. A run that ends in `ERROR` without a fatal in
the server logs (a genuine infra failure) is still preserved as
inconclusive. OOM kills are excluded because the dmesg OOM row carries
no `BLOCKER` label.

Also harden the `FuzzerLogParser` call site: when only one of the
server/stderr logs exists, `str(None)` became the literal path "None"
and `get_stack_trace` failed with `FileNotFoundError`; fall back to
whichever log exists.

Co-Authored-By: Claude Fable 5 <[email protected]>
…gregate status

A per-test `ERROR` row caused by the master-HEAD server crash should be
downgraded to `FAIL` even when `FTResultsProcessor` did not set the
aggregate status to `ERROR` - the inverter treats any per-row `ERROR`
as inconclusive, not only the aggregate one.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Continued work on this PR (2026-07-19):

  • Merged master (branch was ~2100 commits behind; clean merge). The merged binary was rebuilt and both 04512_with_fill_interval_step_int64_overflow and 01662_date_ubsan match their references exactly.
  • Fixed the Bugfix validation red (both arches), which was a harness gap this PR exposed: the regression test reproduces the UBSan overflow on the master-HEAD asan_ubsan binary, and with -fno-sanitize-recover=all that kills the server. The abort surfaced as a runner-level ERROR that invert_bugfix_validation_status preserved as inconclusive (per Bugfix validation harness reports 'Failed to reproduce the bug' when runner does not finish (overwrites genuine ERROR) #105789), so a bugfix whose reproduction crashes the sanitizer server could never validate and new_tests_check.py blocked the PR. Now, when check_fatal_messages_in_logs finds a sanitizer/fatal failure (a blocker-labelled row) in the master-HEAD server logs, the runner abort and the per-test ERROR rows it caused are attributed to that crash and counted as the bug reproducing; a runner ERROR without a fatal (a genuine infra failure) is still preserved as inconclusive. Also hardened the FuzzerLogParser call site, which crashed with FileNotFoundError: 'None' when only one of the server/stderr logs exists ("Failed to parse sanitizer/fatal failure from server logs" in the last run).
  • Updated the PR description per the AI review's metadata feedback: broader changelog entry covering the add*/subtract* hardening, and the addYearsIndex clamp behavior change on huge deltas is now called out explicitly instead of the stale "behavior is preserved" claim.
  • Integration tests (amd_msan, 7/8): test_replicated_table_structure_alter is the known flake Flaky test: test_replicated_database/test.py::test_replicated_table_structure_alter (regression since 2026-07-10) #110036 (labelled retry_ok with the issue link in the report).
  • Stateless tests (amd_tsan, parallel): 03100_lwu_15_future_reads failed once; the on-runner diagnosis re-ran it 7 times with the same randomized settings and all passed, and CIDB shows it failing on master (2026-07-17, 2026-07-19) and across unrelated PRs, so it is unrelated to this change and has no open issue yet.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110158&sha=6fac17e25bee062f2c959964c0a4df8400576de8&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 (03100_lwu_15_future_reads, also failing on master) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 19, 2026
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Jul 19, 2026
Comment thread ci/jobs/functional_tests.py Resolved
@groeneai

Copy link
Copy Markdown
Collaborator Author

The fix is already in progress and is ours: #109429 "Fix flaky tests 03100_lwu_15_future_reads and 03100_lwu_16_future_reads" (open, not draft). CI-fix only, no engine changes.

Two independent races, both reproduced and validated locally in both directions:

  1. Patch-part count race (03100_lwu_15). After the scenario OPTIMIZE ... FINAL folds both patch parts into the base part, so the background cleanup thread MergeTreeData::clearUnusedPatchParts (default remove_unused_patch_parts=true) legitimately drops them, racing the SELECT sum(rows) FROM system.parts WHERE startsWith(name, 'patch') assertion (expects 200, observes 100 or 0). Data is always correct: sum(v)=799500 with or without patch parts.

  2. wait_for_block_allocated timeout (both tests, shared parts.lib helper). The 100 x 0.3s budget, each iteration doing a synchronous SYSTEM FLUSH LOGS zookeeper_log, could expire under load before the block-create event appeared in system.zookeeper_log; on timeout it printed Failed to wait for block ... to stdout, causing the result differs diff. Budget raised to ~90s and the failure moved to stderr with a non-zero return (matching sibling helpers wait_for_delete_empty_parts / wait_for_delete_inactive_parts), so a genuine timeout fails loudly instead of corrupting stdout.

CIDB matches your observation: 03100_lwu_15_future_reads failed on master on 2026-07-17 and 2026-07-19, plus 5 unrelated PRs in the last 14 days.

The master-HEAD crash downgrade (a BLOCKER fatal in the server logs means
the changed tests reproduced the bug and crashed the server, so its ERROR
rows must become FAIL for the inverter to count a reproduction) only ran for
build_types[0]. A crash-only repro on a later build type (amd_tsan /
amd_msan / amd_debug) still arrived as a runner-level ERROR plus a BLOCKER
fatal, was recomputed to FAIL by extend_sub_results, then unconditionally
restored to ERROR, and invert_bugfix_validation_status preserved it as
inconclusive (ClickHouse#105789) instead of a valid reproduction.

Factor the build_types[0] reconciliation into reconcile_bugfix_crash_repro
and reuse it for the build_types[1:] loop so the crash-as-reproduction
handling is identical across all bugfix-validation build types.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
The later build types (build_types[1:]) reconciliation added in the previous
commit had no focused coverage: the WITH FILL overflow this PR fixes reproduces
on build_types[0], so a bugfix-validation run short-circuits before the later
loop, and the existing inverter suite starts after reconciliation. Add four
tests around reconcile_bugfix_crash_repro that start from
runner_level_error + per-test ERROR rows + a BLOCKER fatal and assert the
later-build-type result becomes FAIL (then OK via the inverter), while a
genuine infra ERROR without a BLOCKER fatal is preserved as inconclusive.

The tests call the helper directly (not through main's build-type loop, which
swaps binaries and reads real server logs), so they guard the reconciliation
logic itself rather than the caller wiring.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — ce605a2f5760c8888547480d0158f96fd49bff68

CI fully finished after the master merge (Finish Workflow + Mergeable Check green). One failure, not PR-caused (this PR touches only FillingTransform interval-kind overflow handling; the failure is a chronic DatabaseReplicated DDL-recovery race).

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 3/6) / test_replicated_database::test_replicated_table_structure_alter flaky (chronic DDL-recovery race: 506 PRs / 1120 hits / 103 master, 30d) #111029 (external, open)

Session id: cron:our-pr-ci-monitor:20260720-163000

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, please resolve conflicts.

…ill-interval-step-int64-overflow

# Conflicts:
#	src/Functions/FunctionDateOrDateTimeAddInterval.h
@groeneai

Copy link
Copy Markdown
Collaborator Author

Conflicts are already resolved by your master merge (440bbbb); the branch is now mergeable and CI is running. I verified current master (49302f6) still merges cleanly on top, so I won't push a redundant merge.

@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.10% +0.10%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 84/93 (90.32%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 440bbbbbb8d9ce4fd7ac629f4ea6fc6d08d2a1e1

CI fully finished after the 07-21 master merge (Finish Workflow green; only CH Inc sync still pending, which is the private upstream-sync check, no-owner exempt). This PR's diff is a signed-overflow fix in FillingTransform gated behind WITH FILL STEP; neither failure below is in a code path it touches. Every failure has an owner.

Check / test Reason Owner / fixing PR
Integration tests (amd_tsan, 3/6) / test_replicated_database::test_replicated_table_structure_alter flaky (chronic DatabaseReplicated DDL-recovery race) #111029 (external, open)
Performance Comparison (arm_release, master_head, 6/6) perf-runner shard-level ERROR (no artifacts uploaded; siblings 1/6-5/6 OK) a fix task is created (investigating at full effort; fixing-PR link to follow here)
Mergeable Check / PR rollup of the above owned via the two lines above
CH Inc sync private upstream sync CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260722-013000

@vdimir
vdimir added this pull request to the merge queue Jul 22, 2026
@vdimir
vdimir removed this pull request from the merge queue due to a manual request Jul 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 22, 2026
Merged via the queue into ClickHouse:master with commit becbbea Jul 22, 2026
697 of 702 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 22, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…nstruction

The AI review pointed out that `mulStepWrapping` only fixes the outer
`step * jumps_count` multiply: `FillingRow::doLongJump` can still hand
`delta == -2^63` to `AddMinutesImpl` / `AddHoursImpl`, whose `UInt32`
(`DateTime`) and `DateTime64` overloads multiplied it again as signed
`Int64` (`delta * 60`, `delta * 3600`) - undefined behavior that was
merely uninstrumented via `NO_SANITIZE_UNDEFINED`, not defined.

Compute those overloads (and the `AddSecondsImpl` addition) in the
`UInt64` domain instead: bit-identical to the previous two's complement
behavior for all inputs, but well-defined. Drop `NO_SANITIZE_UNDEFINED`
from the rewritten overloads so UBSan now enforces the property - the
existing MINUTE/HOUR cases in
`04512_with_fill_interval_step_int64_overflow` drive `delta` to
`-2^63` and exercise the helper multiplies under the sanitizer.

ClickHouse#110158

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…oads

`WITH FILL STEP INTERVAL 32768 WEEK STALENESS INTERVAL 1 DAY` on a
`Date` column stalls `FillingRow::doLongJump` the same way the DateTime
MINUTE/HOUR cases do (`32768 * 7 == 2^15 (mod 2^16)`: odd jumps advance,
even jumps stall), so `AddWeeksImpl::execute` for `UInt16` received
deltas up to the wrapped `-2^63` and multiplied them by 7 as signed
`Int64` - verified empirically with a `__builtin_mul_overflow` probe
(overflows at delta = 2^61, 2^62, -2^63). Rewrite the `UInt16`/`Int32`
overloads of `AddDaysImpl` and `AddWeeksImpl` in the `UInt64` domain as
well (bit-identical for all inputs) and add the `WEEK` regression case.

ClickHouse#110158

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…fill-interval-step-int64-overflow

Fix signed integer overflow in FillingTransform interval-kind WITH FILL STEP
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 manual approve Manual approve required to run CI pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants