Repository navigation
Fix the nightly libFuzzer OOM and timeout - #118286
Conversation
The `NightlyFuzzers` run at 8d8dd30 failed with two findings. `data_type_deserialization_fuzzer` ran out of memory (used 8235 Mb, limit 8192 Mb) with 5.5 GB of live heap in `DateLUT::getImplementation`. `cctz` synthesizes a zone for every name of the form `Fixed/UTC±HH:MM:SS` without consulting the time zone database, and accepts any offset up to 24 hours, which is 172801 distinct names. Every name that gets loaded permanently costs ~4.6 MiB in the `DateLUT` cache, and that cache never evicts anything because callers keep bare references into it, so untrusted input could make the server allocate memory that it never gives back: 1 name costs 187 MB of RSS, 180 names cost 989 MB, 600 names cost 2964 MB. Accept only the offsets a time zone can actually have: a whole number of quarters of an hour, no further from UTC than 14 hours. That covers every offset in the time zone database - the last one that was not a multiple of 15 minutes ended in 1972 - and leaves 113 such names, which bounds the cache. `Values::OffsetChangeFactor` already assumes the same granularity for the offset changes within a zone. The `session_timezone` setting validates through the same predicate, so a value cannot be accepted and then fail on every query. `select_parser_fuzzer` hit its 60 second per-input timeout while still replaying its own corpus. Its seed corpus is generated from `tests/queries`, whose largest file is ~380 KB, and without an explicit `max_len` libFuzzer sizes every input after that file. The 334 KB input it timed out on parses in 0.28 s of CPU in a release build, so nothing is wrong with the parser - a query that long just cannot be parsed within 60 seconds by a sanitizer build. Cap the input length at 65536, the same cap `create_parser_fuzzer` already uses. The statistics the report printed for both targets were nonsense - "replaying the initial corpus took 19701 of 140 executed inputs (14072%), leaving -19561 mutations". `parse_libfuzzer_output` split each line before testing it, which strips indentation, so the frames of a sanitizer stack trace were taken for libFuzzer progress lines and the last frame's depth was reported as the number of executed inputs. Anchor the progress line at the start of the line and require its event to be a word: the run above then reports 34930 executed inputs with the rest of its statistics intact. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=8d8dd308b73c4bb8ef921f0b01f6806656054872&name_0=NightlyFuzzers&name_1=libFuzzer%20tests Related: #107459
|
Workflow [PR], commit [25b1e15] Summary: ✅
AI ReviewSummaryRestricts synthetic PR Metadata
Findings❌ Blockers
Final Verdict❌ Changes requested. The shared LLVM Coverage ReportMeasured on commit 25b1e15.
Changed lines: Changed C/C++ lines covered: 32/34 (94.12%) · Uncovered code |
| if (&inside_main) | ||
| chassert(inside_main); | ||
|
|
||
| if (!isSupportedTimeZoneName(time_zone)) |
There was a problem hiding this comment.
This turns a fuzzer hardening change into a backward-incompatible type change. DateTime(...) and DateTime64(..., ...) persist the time zone string in stored metadata and binary type encodings, and both ATTACH/metadata loading (InterpreterCreateQuery::getColumnType) and Native type decoding rebuild them through TimezoneMixin -> DateLUT::instance(time_zone_name). After this guard, an older table or Native stream that uses something like DateTime64(3, 'Fixed/UTC-00:44:30') starts throwing BAD_ARGUMENTS on deserialization even though older versions accepted and could write that schema.
If the goal is only to bound untrusted runtime inputs, this check needs to stay out of unconditional DateLUTImpl construction: scope it to the relevant entry points, or gate/apply it only to newly created metadata so already-stored schemas remain readable.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units2719 translation units recompiled, 14713 s compile time in total, 2719 of them have a recent master baseline. |
|
TL;DR: the compatibility concern raised in review turned out to be worse in practice, so I filed #118353 with an empirical reproduction.
A control table with an on-grid name ( |
`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. ClickHouse#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]>
`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]>
Fixes the two failures in the nightly libFuzzer run at
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=8d8dd308b73c4bb8ef921f0b01f6806656054872&name_0=NightlyFuzzers&name_1=libFuzzer%20tests
Related: #107459
data_type_deserialization_fuzzerran out of memoryout-of-memory (used: 8235Mb; limit: 8192Mb), with 5.5 GB of live heap inDateLUT::getImplementation. This is server behaviour, not a fuzzer artifact.cctzsynthesizes a zone for every name of the formFixed/UTC±HH:MM:SSwithoutconsulting the time zone database, and accepts any offset up to 24 hours - 172801 distinct
names. Each name that gets loaded permanently costs ~4.6 MiB in the
DateLUTcache, andthat cache never evicts anything because callers keep bare
const DateLUTImpl &referencesinto it. Measured on master:
So
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 that
it never gives back.
These names cannot simply be rejected: reading an Arrow or ORC timestamp column with a
fixed-offset time zone deliberately produces them (
03926_arrow_fixed_offset_timezone).Instead, only the offsets that a time zone can actually have are accepted - a whole number
of quarters of an hour, no further from UTC than 14 hours. That covers every offset in the
time zone database (the last one that was not a multiple of 15 minutes ended in 1972) and
leaves 113 such names, which bounds the cache.
DateLUTImpl::Values::OffsetChangeFactoralready assumes the same granularity for the offset changes within a zone.
SettingFieldTimezone::validateTimezonegoes through the same predicate, so asession_timezonevalue cannot be accepted and then fail on every query.This does not fix #107459 - enumerating the 597 names of the time zone database still
accumulates ~2.9 GB - it stops that accumulation from being unbounded.
select_parser_fuzzerhit its per-input timeoutlibFuzzer: timeout after 60 seconds, while the target was still replaying its own corpus(19701 of the 19686 corpus files, at 9 exec/s).
Nothing is wrong with the parser: the 334 KB input it timed out on parses in 0.28 s of CPU
in a release build. The target's seed corpus is generated from
tests/queries, whose largestfile is ~380 KB, and with no explicit
max_lenlibFuzzer sizes every input after that file(
lim: 381493), so it both replays and mutates inputs that a sanitizer build cannot parsewithin 60 seconds. Capped at 65536, the same cap
create_parser_fuzzeralready uses.The report's statistics were nonsense
parse_libfuzzer_outputsplit each line before testing it, which strips indentation, so theframes of a sanitizer stack trace (
#140 0xaada2314ee40 in DB::ParserCollectionOfLiterals...)were taken for libFuzzer progress lines, and the depth of the last stack frame was reported as
the number of executed inputs. Both failing targets reported a stack depth. Anchoring the
progress line at the start of the line and requiring its event to be a word, the same two logs
now parse as:
select_parser_fuzzerexecuted 140 inputsexecuted 34930 inputs, exec/s: 8, cov: 16848, ft: 82000, corp: 8468/16Mb, rss: 1759Mbdata_type_deserialization_fuzzerexecuted 28 inputsexecuted 665212 inputs, exec/s: 88, cov: 25383, ft: 120615, corp: 15862/6631Kb, rss: 8235MbChangelog 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
Fixed/UTC±HH:MM:SS. Every distinct name permanently cost ~4.6 MiB that the server never gave back, and 172801 of them were accepted. Only offsets that a time zone can have are accepted now: a whole number of quarters of an hour, no further from UTC than 14 hours.Workflow [PR]
Sync PR [sync-upstream/pr/118286]
Version info
26.9.1.825(included in26.9and later)