Skip to content

formatDateTimeInJodaSyntax: Fix potential memory overwrite with overlong time zones - #117925

Merged
rschu1ze merged 1 commit into
masterfrom
formatDateTime-extralong-timezone
Sep 4, 2026
Merged

rschu1ze merged 1 commit into
masterfrom
formatDateTime-extralong-timezone

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

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

Fixes a potential out-of-bounds write of function formatDateTimeInJodaSyntax when called with a time zone name longer than 32 characters.


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

Version info

  • Merged into: 26.9.1.681 (included in 26.9 and later)
  • Backported to: 26.8.3.31, 26.7.7.25, 26.6.5.46, 26.3.33.4

@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 3, 2026
@rschu1ze
rschu1ze marked this pull request as ready for review September 3, 2026 18:02
@rschu1ze rschu1ze changed the title formatDateTimeInJodaSyntax: Fix potential memory overwrites with overlong time zones formatDateTimeInJodaSyntax: Fix potential memory overwrite with overlong time zones Sep 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7cb7f70]

Summary: ✅


AI Review

Summary

This PR fixes the 32-byte overwrite in Joda timezone formatting by throwing once the stored timezone spelling exceeds 32 bytes. I do not think the current approach is ready to merge, because it turns the memory-safety fix into a user-visible behavior regression for timezone names that DateLUT still accepts elsewhere.

Findings

⚠️ Majors

  • [src/Functions/formatDateTime.cpp:857] The implementation now rejects any validated timezone spelling longer than 32 bytes, but DateLUT keeps the original spelling and cctz accepts zoneinfo paths with repeated separators. Queries such as formatDateTimeInJodaSyntax(..., 'zzzz', 'Etc///////////////////////////UTC') are therefore valid in the existing timezone surface and now fail only in the Joda formatter. The broken contract here is "any timezone that ClickHouse accepts remains formattable"; the fix should size the reservation from the actual validated timezone string instead of imposing a new 32-byte ceiling. Suggested fix: extract constant/type-attached timezones before parseFormat and reserve their actual length; for non-constant timezone arguments, pre-scan the column for the maximum validated spelling length or route z through a variable-width path.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 7cb7f70.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.00% 81.00% +0.00%

Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 3, 2026
@rschu1ze
rschu1ze force-pushed the formatDateTime-extralong-timezone branch from ca4b3f2 to 7cb7f70 Compare September 3, 2026 18:04

auto str = timezone.getTimeZone();
if (str.size() > MAX_JODA_TIMEZONE_NAME_LENGTH)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Time zone name is longer than the maximum supported length of {} bytes", MAX_JODA_TIMEZONE_NAME_LENGTH);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

DateLUT preserves the validated timezone spelling verbatim, and upstream cctz loads it by appending that string to the zoneinfo path without collapsing repeated separators first. That means names like Etc///////////////////////////UTC are still valid timezones in the rest of ClickHouse, but this new guard makes formatDateTimeInJodaSyntax/fromUnixTimestampInJodaSyntax reject them purely because the spelling is longer than 32 bytes.

So this changes the function contract instead of just fixing the buffer sizing bug. Please reserve from the actual validated timezone string for constant/type-attached timezones, and pre-scan the timezone column (or treat z as variable-width) for non-constant arguments, rather than rejecting accepted timezone names here.

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7cb7f70e3 with master 2400b5ade (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of dfde23932; 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

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

Job report

@rschu1ze
rschu1ze added this pull request to the merge queue Sep 4, 2026
Merged via the queue into master with commit f73529f Sep 4, 2026
174 checks passed
@rschu1ze
rschu1ze deleted the formatDateTime-extralong-timezone branch September 4, 2026 09:43
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 4, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 4, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 4, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 4, 2026
… memory overwrite with overlong time zones
clickhouse-gh Bot added a commit that referenced this pull request Sep 4, 2026
Backport #117925 to 26.8: `formatDateTimeInJodaSyntax`: Fix potential memory overwrite with overlong time zones
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 4, 2026
… memory overwrite with overlong time zones
clickhouse-gh Bot added a commit that referenced this pull request Sep 4, 2026
Backport #117925 to 26.6: `formatDateTimeInJodaSyntax`: Fix potential memory overwrite with overlong time zones
clickhouse-gh Bot added a commit that referenced this pull request Sep 4, 2026
Backport #117925 to 26.7: `formatDateTimeInJodaSyntax`: Fix potential memory overwrite with overlong time zones
rschu1ze added a commit that referenced this pull request Sep 6, 2026
Backport #117925 to 26.3: `formatDateTimeInJodaSyntax`: Fix potential memory overwrite with overlong time zones
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
… potential memory overwrite with overlong time zones
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
… potential memory overwrite with overlong time zones
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
OTHER: formatDateTimeInJodaSyntax with a time zone name longer than 32 characters overflows a fixed buffer.
Effect in the production build a394e92: crash (any user, one SELECT) (the upstream test fails on it and passes on
official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro). Upstream patch unchanged, with its test(s): 05059_formatDateTime_extralong_timezone

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…fixes

05059_formatDateTime_extralong_timezone (ClickHouse#117925) and 04327_join_runtime_filter_json
(ClickHouse#107663) join the stateless selection (97 tests); known_defects.json gets their
entries (40, 0 open).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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