Repository navigation
Conversation
Three related edge-case bugs surface as P0 sanitizer reports on the
`Unit tests (msan|asan_ubsan, function_prop_fuzzer)` master job
(originally from the libFuzzer-driven function property fuzzer):
1. `src/Parsers/Lexer.cpp:119` — `Lexer::nextToken` computes
`begin + max_query_size` unconditionally. When the fuzzer constructs
a `Lexer` with `begin == nullptr` and a non-zero `max_query_size`,
UBSan reports:
applying non-zero offset 262144 to null pointer
Guard the arithmetic with a `begin != nullptr` check.
2. `src/Functions/URL/protocol.h:17` — `getURLScheme` dereferences
`*pos` before checking `size`. With `size == 0` the read goes
one byte past the buffer. In production `ColumnString` padding
hides this, but the fuzzer drives the function with unpadded
buffers and MSan flags a use-of-uninitialized-value. Short-circuit
the empty-input case before touching `*pos`.
3. `src/Common/UTF8Helpers.cpp` — `UTF8::convertUTF8ToCodePoint`
forwards straight to `Poco::UTF8Encoding::queryConvert`, which
reads the first byte without length-check, yielding
MSan: use-of-uninitialized-value at UTF8Encoding.cpp:156:10
Callers naturally pass `end - pos` which can be zero at string
boundaries (`HasSubsequenceImpl.h`, `Volnitsky.h`, `StringSearcher.h`,
`translate.cpp`, `initcapUTF8.cpp`, `FunctionsStringDistance.cpp`).
Fix the root cause at `convertUTF8ToCodePoint` by returning empty
for zero-length input; this also eliminates the
`Volnitsky.h:724/475 putNGramBase` MSan signature for free.
Regression tests:
- `src/Parsers/tests/gtest_Lexer.cpp` — deterministic UBSan reproducer
for the null-begin case, plus sanity coverage for a real query and
for an empty-but-non-null buffer.
- `tests/queries/0_stateless/04113_sanitizer_empty_string_ops.sql`
— exercises `protocol('')` and `hasSubsequenceCaseInsensitiveUTF8`
with empty haystack/needle combinations (both ASCII and UTF-8).
The Lexer repro was validated locally against an ASan+UBSan build:
without the fix, running `LexerTest.NextTokenWithNullBeginAndMaxQuerySize`
fires UBSan at the exact CIDB signature (`Lexer.cpp:119:43`); with the
fix, the test passes.
|
cc @alexey-milovidov @rschu1ze — could you review this? It addresses three sanitizer findings accumulating on the |
Pre-PR validation gatea) Deterministic repro? Yes — This matches the CIDB signature byte-for-byte. The MSan findings ( b) Root cause explained?
c) Fix matches root cause? Yes, each fix targets the identified mechanism:
d) Test intent preserved? / New tests added? Yes — no existing tests were weakened. New tests:
e) Both directions demonstrated? For the Lexer bug, yes — verified locally. Confirmed sequence:
The MSan fixes are backed by code analysis + regression tests and will be verified by the f) Fix is general, not a narrow patch? Yes — the Session: |
|
See also #102302 |
|
Workflow [PR], commit [85a52f2] AI ReviewSummaryThis PR fixes three sanitizer-reported edge cases ( ClickHouse Rules
Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: 100.00% (26/26) | lost baseline coverage: 4 line(s) · Uncovered code |
|
Thanks for the pointer to #102302 @alexey-milovidov. Closing this PR as superseded — PR #103489 was merged ~2h ago by @yakov-olkhovskiy landing identical fixes for all three areas this PR covered: Master status (CIDB, 2026-04-24 12:45 UTC):
The unique delta in this PR was moving the UTF-8 guard from |
Summary
Unit tests (msan, function_prop_fuzzer)andUnit tests (asan_ubsan, function_prop_fuzzer)have been reporting three distinct sanitizer findings on master for the past week. CIDB over the last 3 days shows 12 master hits across all three signatures, with 50+ PRs polluted per day as the same bugs surface on unrelated changes:src/Parsers/Lexer.cpp:119:43—applying non-zero offset 262144 to null pointerbegin + max_query_sizewithbegin != nullptrsrc/Functions/URL/protocol.h:17:9ingetURLScheme(viaprotocol(...))size == 0before dereferencing*possrc/Common/UTF8Helpers.cpp:156:10inPoco::UTF8Encoding::queryConvert(propagated fromUTF8::convertUTF8ToCodePoint)convertUTF8ToCodePoint— root-cause fix that also covers theVolnitsky.hputNGramBaseMSan signature and every other caller (HasSubsequenceImpl.h,StringSearcher.h,translate.cpp,initcapUTF8.cpp,FunctionsStringDistance.cpp)In production the
protocol.handconvertUTF8ToCodePointreads are typically covered byColumnStringpadding, so end users are not affected. The function property fuzzer drives these functions with unpadded buffers, which is where the sanitizers fire.An earlier AI-authored attempt at these fixes was opened in #103483 and closed by the author the same day (
cleaning AIs mess). The parent PR #99740 contains thegetURLSchemeguard but has been blocked on unrelated libFuzzer CI work since March, so the trunk bugs keep accumulating. This PR re-applies the three fixes under a signed-off commit, adds regression tests, and fixes the MSanqueryConvertsignature at its root rather than guarding individual callers.Reproduction and validation
The
Lexernull-begin bug is deterministically reproducible under an ASan+UBSan build:With the fix applied, all three
LexerTestcases pass. The SQL regression test04113_sanitizer_empty_string_opspasses against the ASan binary.Matching CIDB master hits this week:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix sanitizer findings in
function_prop_fuzzerunit-test job: null-pointer arithmetic inLexer::nextToken, reading past empty-string buffer ingetURLScheme, and zero-lengthPoco::UTF8Encoding::queryConvertcall fromUTF8::convertUTF8ToCodePoint.Documentation entry for user-facing changes