Repository navigation
Forbid libc: time zone names - #119634
Forbid libc: time zone names#119634
libc: time zone names#119634Conversation
`cctz` resolves every name of the form `libc:<suffix>` through the C library instead of the time zone database. `libc:localtime` and `libc:UTC` are its own internal, test-only interfaces, and any other suffix is accepted just as well and silently behaves as UTC. The suffix is unrestricted, so this family of accepted names has no bound, and every name that gets loaded permanently costs ~4.6 MiB in the `DateLUT` cache, which never evicts anything because callers keep bare `const DateLUTImpl &` references into it. Measured at 4.60 MiB of peak RSS per distinct name, growing linearly. This is the second such family. #118286 bounded `Fixed/UTC±HH:MM:SS`, but `isSupportedTimeZoneName` returns true for every name that does not start with `Fixed/`, so the nightly `data_type_deserialization_fuzzer` has run out of memory every night since, with its live heap in `DateLUT::getImplementation`. 50 files of that target's corpus contain `libc:`, while `Fixed/UTC` and `posix/` appear in none, and libFuzzer blamed the empty input on four of the eight nights - the growth is cumulative, not the fault of one input. Rejecting the prefix also stops `toDateTime(0, 'libc:whatever')` from answering with a UTC value instead of reporting the name back. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=30c98e714f85f24e60583935bbe38b5bbb65aa2d&name_0=NightlyFuzzers&name_1=libFuzzer%20tests&name_1=libFuzzer%20tests Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [9e58a42] Summary: ✅
AI ReviewSummaryThis PR closes the unbounded Findings❌ Blockers
Tests
Final VerdictChanges requested. The OOM fix itself looks sound, but the shared rejection path introduces a backward-incompatible upgrade failure for previously persisted LLVM Coverage ReportMeasured on commit 9e58a42.
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
|
🕵 The only red check, |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only tightens time-zone name validation in DateLUTImpl (rejecting the unbounded clickbenchFlagged queries (3 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
🕵 Public CI on 9e58a42 is fully green (154 checks). The only pending item is
@groeneai, investigate the last two failures and provide fixes in separate PRs. If fixes are already in progress, link them here. |
|
Acknowledged, I am taking both. No fix PR is open for either one yet.
The I will post each PR link in this thread as it opens. |
|
🕵 Thanks @groeneai. Status note on |
|
I looked at the second failure, the TSan race in The writer looks guilty in the stack but is not. A correctly locked reader could not have produced this report. Which read it was. Two of the four The fix. auto part_lock = data->lockParts();
auto active_part = data->getActiveContainingPart(cloned_part.part->name, part_lock);Worth noting that this covers a second consumer: the same Why there is no PR from me. One thing I could do publicly if you want it: make The first failure, the |
|
🕵 Thanks @groeneai, the On |
|
I will open the assertion as its own small PR, not here. Shape: the two I checked the existing public token sites before promising it, so the assertion should not fire on master paths. The closest case is the four size getters that hand their
|
|
I measured first, as promised, and it took both remedies. The four resizable abandon cases were sized by the arming threshold of One thing the resizing exposed: those cases asserted nothing about abandoning, because result equality and the |
|
The It stays a diagnostic, active only in debug and sanitizer builds; the |
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
`isSupportedTimeZoneName` was a deny-list of two prefixes, `libc:` and `Fixed/`, so acceptance of every other name was delegated to whatever `cctz`'s filesystem fallback could open. That set is not the time zone database. `cctz` resolves a name as a path under the time zone database directory, and with a `file:` prefix as an arbitrary path, so one zone has unboundedly many names: `Europe/./Amsterdam`, `Europe//Amsterdam`, `file:UTC`, `file:/usr/share/zoneinfo/UTC`, and any number of repetitions of `./` and `/`. None of them is in `system.time_zones`, and every distinct name that gets loaded permanently costs ~4.6 MiB in the `DateLUT` cache, which never evicts anything because callers keep bare references into it. So the cache that the two previous fixes were bounding was still unbounded, reachable through `toDateTime(x, '<name>')`, the `session_timezone` setting, binary type decoding, or the time zone of an Arrow or ORC timestamp column. Peak RSS of `clickhouse-local`, before this change: 20 uses of `Europe/Amsterdam` 182 MB 20 distinct `./`-padded spellings of `Europe/Amsterdam` 303 MB 100 distinct `./`-padded spellings of `Europe/Amsterdam` 683 MB 100 distinct `file:` spellings of `UTC` 679 MB `file:` was also a way to read a file outside the time zone database directory, which is exactly what the `CheckTimeZoneName` guard vendored into `contrib/cctz` exists to prevent: a TZif file copied anywhere on the filesystem loaded and answered as that zone. The open happened while `DateLUT::getImplementation` held its global mutex, so a name pointing at a FIFO or a hung network mount would have blocked every time zone lookup server-wide. Make the check an allow-list: a name is accepted only if it is in the time zone database linked into the binary - which is exactly what `system.time_zones` lists, and what the documentation of the `DateTime` type and of `session_timezone` already tell users to use - or if it is one of the 114 `Fixed/UTC±HH:MM:SS` names for the offsets a time zone can really have. So the cache holds at most 712 entries. This closes the padded spellings and the `file:` prefix in one line, subsumes the `libc:` prefix, and makes the message the check reports true. The `cctz` fallback in `custom_factory` is dropped as well, so no name can reach the host's filesystem even if it gets past the predicate. Names that only the host's time zone database has are no longer accepted. ClickHouse ships its own tzdata precisely so that results do not depend on the host, such a name is absent from `system.time_zones`, and `timezone()` answering a name that no user can spell is itself wrong. The one place where the host chooses the name is the server's own local time zone, so `DateLUT` reports that case at startup, naming the zone and how to override it. This does not make the cache small - the 598 names of the time zone database plus the 114 fixed offsets still reach ~3.2 GB if all of them are used - it makes it bounded. Shrinking a `DateLUTImpl`, or evicting entries, is a separate matter (ClickHouse#107459). A misspelled time zone name is now reported as "Time zone X is not supported. Use a name from `system.time_zones`, ..." instead of "Cannot load time zone X", so `03926_arrow_fixed_offset_timezone` is updated. `05059_formatDateTime_extralong_timezone` checked the 32-byte limit that `formatDateTimeInJodaSyntax` puts on a time zone name, using `'Etc' || repeat('/', 26) || 'UTC'` to reach exactly 32 bytes. That spelling is one of the ones this rejects, and the longest real name, `America/Argentina/ComodRivadavia`, is exactly 32 bytes, so the test uses it instead: the name the per-row reservation has to fit is a real one, and nothing longer can be constructed. Closes: ClickHouse#120188 Related: ClickHouse#119634 Related: ClickHouse#118286 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: #118286
Fixes the
data_type_deserialization_fuzzerout-of-memory in the nightly libFuzzer run athttps://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=30c98e714f85f24e60583935bbe38b5bbb65aa2d&name_0=NightlyFuzzers&name_1=libFuzzer%20tests&name_1=libFuzzer%20tests
out-of-memory (used: 8235Mb; limit: 8192Mb), with the live heap inDateLUT::getImplementationagain. #118286 bounded one family of names thatcctzsynthesizes itself,
Fixed/UTC±HH:MM:SS. There is a second one, and it is still unbounded:cctzresolves every name of the formlibc:<suffix>through the C library instead of thetime zone database -
TimeZoneIf::Makeroutes it toTimeZoneLibC::Make, which never failsfor any suffix.
libc:localtimeandlibc:UTCarecctz's own internal, test-onlyinterfaces, documented as "subject to change/removal without notice. Do not use them", and
any other suffix is accepted just as well and silently behaves as UTC.
isSupportedTimeZoneNamereturns true for every name that does not start with
Fixed/, so all of them are accepted.The suffix is unrestricted, so this family has no bound at all, and every name that gets
loaded permanently costs ~4.6 MiB in the
DateLUTcache, which never evicts anything becausecallers keep bare
const DateLUTImpl &references into it. Measured on master, linear:libc:names usedSo
toDateTime(x, '<name>'), thesession_timezonesetting, binary type decoding and thetime zone of an Arrow or ORC timestamp column could all make the server allocate memory
without bound that it never gives back.
That the fuzzer reaches this: 50 files of its current corpus contain
libc:, whileFixed/UTCandposix/appear in none - theFixed/cap from #118286 is holding, and thisis what is left. The arithmetic agrees too: 5.78 GB of live heap is ~1231 instances, where the
597 names of the time zone database plus all 113 legal fixed offsets can only reach 710. And
libFuzzer blamed the empty input (
oom-da39a3ee5e6b4b0d3255bfef95601890afd80709) on four ofthe eight failing nights, which is what cumulative growth looks like: no single input is at
fault, the target just crosses the RSS limit eventually.
Nothing legitimate names these zones, so the whole prefix is rejected. Unlike
Fixed/UTC±HH:MM:SS, which reading an Arrow or ORC timestamp column with a fixed-offset timezone deliberately produces,
libc:names appear nowhere insrcortests, and they areabsent from
system.time_zones. Rejecting them also stopsSELECT toDateTime(0, 'libc:whatever')from answering1970-01-01 00:00:00instead ofreporting the name back.
SettingFieldTimezone::validateTimezonegoes through the same predicate, so asession_timezonevalue cannot be accepted and then fail on every query.This does not make the cache bounded in absolute terms - enumerating the 597 names of the time
zone database still accumulates ~2.9 GB, the residue of #107459 that #118286 already noted - it
removes the second way to grow it without bound.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix unbounded memory growth from time zone names of the form
libc:<suffix>. These are internal interfaces of thecctzlibrary that ClickHouse never intended to expose: any suffix was accepted, each distinct name permanently cost ~4.6 MiB that the server never gave back, and the time zone silently behaved as UTC instead of the name being reported as unknown. They are rejected now.Workflow [PR]
Sync PR [sync-upstream/pr/119634]
Version info
26.9.1.1486(included in26.9and later)