Skip to content

Reject out-of-range IntervalKind during binary type decoding - #106261

Merged
nikitamikhaylov merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-3285-3bba-siphash-empty-buffer
Jun 5, 2026
Merged

nikitamikhaylov merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-stid-3285-3bba-siphash-empty-buffer

Conversation

@groeneai

@groeneai groeneai commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: STID 3285-3bba (no public tracker)
Related: #106469

decodeDataType in src/DataTypes/DataTypesBinaryEncoding.cpp for BinaryTypeIndex::Interval cast a UInt8 byte read from the input buffer directly to IntervalKind::Kind (valid range 0x00..0x0A) without any range validation. Anything in 0x0B..0xFF produced a DataTypeInterval whose internal kind was out of range. IntervalKind::toString then returned magic_enum::enum_name on an unknown value, which on libcxx is std::string_view{nullptr, 0}, and SerializationInterval::getHash fed that null pointer into SipHash::update. UBSan flagged the data + 8 evaluation in SipHash::update via -fsanitize=pointer-overflow (STID 3285-3bba in the AST fuzzer).

This PR rejects out-of-range IntervalKind bytes at the deserialization site with INCORRECT_DATA. That stops the bad enum value from ever existing, so the downstream IntervalKind::toString -> magic_enum::enum_name -> empty string_view path never executes for crafted/malformed input.

The defense-in-depth SipHash::update size==0 short-circuit (and its gtest) was split out per @azat into PR #106469 so this PR remains a focused, backportable bug fix.

Audit / symmetric paths

IntervalKind is constructed from external bytes in only one place: DataTypesBinaryEncoding.cpp. Other entry points are safe:

  • ArrowColumnToCHColumn.cpp:151-161 — closed-enum switch with UNKNOWN_TYPE fallback
  • parseIntervalKind.cpp — string-keyword based
  • parseTimeSeriesTypes.cpp:61 — forwards from validated parser path

Test

tests/queries/0_stateless/04307_03285_3bba_interval_binary_encoding_invalid_kind.sh feeds three malformed bytes (0x0B, 0x7F, 0xFF) through RowBinaryWithNamesAndTypes with input_format_binary_decode_types_in_binary_format and asserts each is rejected with Code: 117. DB::Exception: Unknown IntervalKind during Interval type decoding: 0xNN. (INCORRECT_DATA).

Reproduction (CI)

CI report where the original UBSan trip surfaced: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106251&sha=874c4f0fc6fa05c7726121221bd18e4185eda64e&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29

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

Reject out-of-range IntervalKind bytes during RowBinaryWithNamesAndTypes type decoding (input_format_binary_decode_types_in_binary_format = 1) with a clear INCORRECT_DATA error instead of constructing a DataTypeInterval with an invalid kind that could subsequently trip undefined behavior in hash paths.

Documentation entry for user-facing changes

  • Documentation is unchanged: this rejects invalid input that previously produced an internal undefined-behavior path.

Version info

  • Merged into: 26.6.1.425 (included in 26.6 and later)
  • Backported to: 26.3.33.44

The AST fuzzer (STID 3285-3bba) tripped UndefinedBehaviorSanitizer at
`src/Common/SipHash.h:134:21` with `applying non-zero offset 8 to null
pointer`. The path was:

  SerializationInterval::getHash(IntervalKind)
    -> SipHash::update(std::string_view sv)         # SipHash.h:183
    -> SipHash::update(sv.data(), sv.size())        # update(const char *, UInt64)
    -> while (data + 8 <= end)                       # SipHash.h:134:21 (UB)

`IntervalKind::toString` returns `magic_enum::enum_name(kind)`, which on
libcxx returns an empty `std::string_view` with `data() == nullptr` and
`size() == 0` whenever `kind` is not a declared enum value (which the AST
fuzzer can produce by mutation). Even though the `while` loop body is never
entered (the condition `nullptr + 8 <= nullptr` is false), evaluating
`data + 8` on a null pointer with a non-zero offset is undefined behavior
per [expr.add]/4. UBSan flags it via `-fsanitize=pointer-overflow`.

The minimal fix is to short-circuit at the top of
`SipHash::update(const char *, UInt64)` when `size == 0`. Every caller
benefits: an empty update is a true no-op and the hash state is preserved
identically across `update(non_empty)` and
`update(empty); update(non_empty); update(empty)`. The fix is a no-op for
all valid inputs and `ALWAYS_INLINE` keeps the hot path unchanged.

Reproduced locally with a standalone clang-21 `-fsanitize=undefined
-fno-sanitize-recover=all` program calling the same `data + 8` pattern with
`(nullptr, 0)`: it produces the exact same UBSan message as the CI report
(`runtime error: applying non-zero offset 8 to null pointer`) without the
guard and exits cleanly with the guard. A gtest unit test
(`src/Common/tests/gtest_sip_hash.cpp`) exercises the path on ClickHouse's
own ASan+UBSan unit-tests target.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106251&sha=874c4f0fc6fa05c7726121221bd18e4185eda64e&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29

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

groeneai commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (session cron:clickhouse-ci-task-worker:20260601-213000)

a) Deterministic local repro? Yes. Minimal standalone reproducer (tmp/ubsan_repro/repro.cpp) built with clang-21 -fsanitize=undefined -fno-sanitize-recover=all:

$ ./repro_bug
repro.cpp:47:17: runtime error: applying non-zero offset 8 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior repro.cpp:47:17
exit=1

$ ./repro_fixed   # same source compiled with -DWITH_FIX (the guard)
empty.data() = (nil), empty.size() = 0
ok
exit=0

Exact same UBSan message format as the CI report (applying non-zero offset 8 to null pointer).

b) Root cause explained? SerializationInterval::getHash calls hash.update(kind_.toString()). IntervalKind::toString returns magic_enum::enum_name(kind), which on libcxx returns an empty std::string_view with data() == nullptr and size() == 0 whenever kind is not a declared enum value (which the AST fuzzer produced by mutation). SipHash::update(string_view) forwards (nullptr, 0) into SipHash::update(const char *, UInt64). That function evaluates data + 8 in the while (data + 8 <= end) condition before any size check. nullptr + 8 (non-zero offset on a null pointer) is UB per [expr.add]/4, even though the loop body is never entered (the condition nullptr + 8 <= nullptr is false).

c) Fix matches root cause? Yes. The guard is at the exact UB site (entry of SipHash::update(const char *, UInt64)), not at the caller or in unrelated transform code. All pointer arithmetic in the function is now reached only when size > 0, so data is a real pointer.

d) Test intent preserved? / New tests added? No existing tests modified. Added src/Common/tests/gtest_sip_hash.cpp with two regression tests: (i) UpdateWithEmptyStringViewDoesNotInvokeUB asserts the fix-target path is safe under UBSan, (ii) UpdateWithEmptyStringViewIsNoOp asserts an empty update yields an identical hash to skipping the call entirely (true no-op semantics).

e) Both directions demonstrated? Yes. The standalone repro fails-without-fix (exit 1 + UBSan message) and passes-with-fix (exit 0 + ok) under the same source + same compiler flags + same toolchain. The gtest unit test will exercise the same path on CI's ASan+UBSan unit-tests target.

f) Fix is general, not a narrow patch? Yes. The guard is at SipHash::update(const char *, UInt64) itself, which is the single entry point all update(...) overloads funnel through (the string_view, const char *, and update<T>(const T &) overloads all call this one). Every existing and future caller that passes an empty buffer is now safe, not only SerializationInterval::getHash. I traced upstream: the empty string_view is a legitimate libcxx value, not "bad state from elsewhere" — fixing the caller (e.g. by validating IntervalKind::Kind) would only patch one symptom and leave every other caller exposed.

CI report (PR #106251, AST fuzzer arm_asan_ubsan, STID 3285-3bba): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106251&sha=874c4f0fc6fa05c7726121221bd18e4185eda64e&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29

@groeneai

groeneai commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Avogar @azat — could you review this? It's a one-line UBSan guard at the entry of SipHash::update(const char *, UInt64) to short-circuit when size == 0, fixing an AST-fuzzer-found UB (applying non-zero offset 8 to null pointer) where SerializationInterval::getHash hashed an empty std::string_view returned by magic_enum::enum_name on an out-of-range IntervalKind. Local repro + both-directions validation in the pre-PR gate comment above.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1bccbb5]

Summary: ✅


AI Review

Summary

This PR rejects malformed IntervalKind bytes while decoding binary-encoded data types, and updates the source-level binary encoding table so Year is documented as 0x0A. I found no unresolved correctness, compatibility, or evidence issues in the current diff.

Final Verdict

Status: ✅ Approve

@azat azat 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.

Fix the PR according to my coments

Comment thread src/Common/SipHash.h Outdated
Comment on lines +110 to +114
/// An empty `std::string_view` (e.g. returned by `magic_enum::enum_name` for an
/// out-of-range enum value) has `data() == nullptr` and `size() == 0`. The
/// pointer-arithmetic below (e.g. `data + 8` in the unrolled loop) is undefined
/// behavior on a null pointer with a non-zero offset, even when the loop body
/// is never entered. Short-circuit here to keep the hash state untouched.

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.

First, this should be in a commit description not a comment in the code, save this into your memory please

Secondly, how it is possible to get incorrect "kind" in "IntervalKind::toString", likely during deserialization, so let's fix this instead and also do not forget to add a test

Comment thread src/Common/tests/gtest_sip_hash.cpp Outdated
Comment on lines +18 to +19
ASSERT_EQ(empty.data(), nullptr);
ASSERT_EQ(empty.size(), 0u);

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.

I know you can generate codex, but please try to be "compact", this is not a test for std::string_view, no need to ASSERTs it's internal state, it is obvious that the internal representation is correct

Comment thread src/Common/tests/gtest_sip_hash.cpp Outdated
Comment on lines +7 to +12
/// Regression test for an UndefinedBehaviorSanitizer finding at SipHash.h
/// reported by the AST fuzzer (STID 3285-3bba): "applying non-zero offset 8 to
/// null pointer" inside `SipHash::update(const char *, UInt64)`. The trigger
/// path was `SerializationInterval::getHash` -> `SipHash::update(string_view)`
/// where the string_view came from `magic_enum::enum_name` on an out-of-range
/// `IntervalKind::Kind` and therefore had `data() == nullptr`, `size() == 0`.

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.

All of this comments should be in commit messages, this comments will be outdated, and for this specific case test name is enough to understand the purpose

groeneai and others added 2 commits June 2, 2026 12:07
`decodeDataType` for `BinaryTypeIndex::Interval` cast a `UInt8` byte from
the input buffer directly to `IntervalKind::Kind` without validating that
the value belonged to the enum (valid range `0x00`..`0x0A`). Anything in
`0x0B`..`0xFF` produced a `DataTypeInterval` whose internal `kind` was
out of range, after which `IntervalKind::toString` returned
`magic_enum::enum_name` on an unknown value. On libcxx that returns
`std::string_view{nullptr, 0}`, and `SerializationInterval::getHash` then
fed that null pointer into `SipHash::update`, where the unrolled loop
computed `data + 8` on a null pointer (UB per `[expr.add]/4`). UBSan
flagged it via `-fsanitize=pointer-overflow` (STID 3285-3bba).

The primary fix is at the deserialization site: reject any byte above
`IntervalKind::Kind::Year` with `INCORRECT_DATA`. A regression test
`04307_03285_3bba_interval_binary_encoding_invalid_kind` feeds three
malformed bytes (`0x0b`, `0x7f`, `0xff`) through
`RowBinaryWithNamesAndTypes` with
`input_format_binary_decode_types_in_binary_format` and asserts each is
rejected.

The previous `SipHash::update(nullptr, 0)` short-circuit is kept as
defense-in-depth. The accompanying comment is shortened, and the
explanatory blocks in `gtest_sip_hash.cpp` plus the `ASSERT_EQ` on
`std::string_view` internals are removed per review feedback.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106251&sha=874c4f0fc6fa05c7726121221bd18e4185eda64e&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
Related: ClickHouse#106251

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@groeneai groeneai changed the title Fix UBSan in SipHash::update on empty std::string_view Reject out-of-range IntervalKind during binary type decoding Jun 2, 2026
@groeneai

groeneai commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

@azat, pivoted to a root-cause fix per your direction.

Root cause: decodeDataType for BinaryTypeIndex::Interval in src/DataTypes/DataTypesBinaryEncoding.cpp cast a UInt8 byte directly to IntervalKind::Kind (valid 0x00..0x0A) with no range check. Out-of-range values produced a DataTypeInterval whose IntervalKind::toString returned magic_enum::enum_name on an unknown value (std::string_view{nullptr, 0} on libcxx), which SerializationInterval::getHash then fed into SipHash::update, where the loop computed data + 8 on nullptr.

Fix (HEAD 6ea45ea0d949):

  1. src/DataTypes/DataTypesBinaryEncoding.cpp line 696: reject kind > IntervalKind::Kind::Year with INCORRECT_DATA. This is the only site that constructs an IntervalKind from an external byte; ArrowColumnToCHColumn uses a closed-enum switch with UNKNOWN_TYPE fallback, and the SQL parser only accepts valid keyword names.
  2. tests/queries/0_stateless/04307_03285_3bba_interval_binary_encoding_invalid_kind.sh: feeds three malformed bytes (0x0b, 0x7f, 0xff) through RowBinaryWithNamesAndTypes with input_format_binary_decode_types_in_binary_format and asserts each is rejected. Verified the test FAILs on the previous HEAD (decode succeeds with broken type then downstream UNKNOWN_TYPE) and PASSes on the new HEAD.
  3. src/Common/SipHash.h: comment shortened to the one-line invariant. The size == 0 short-circuit is kept as defense-in-depth (a precondition that update(nullptr, 0) is a no-op).
  4. src/Common/tests/gtest_sip_hash.cpp: removed the narrative blocks and the ASSERT_EQ(empty.data(), nullptr) / ASSERT_EQ(empty.size(), 0u) assertions on std::string_view internals.

All explanatory context now lives in the commit message instead of code comments. PR title and description updated to match the new approach.

build/src/unit_tests_dbms --gtest_filter="SipHash.*" passes (2/2). The new stateless test passes against a fresh debug server.

Comment thread src/Common/SipHash.h Outdated
ALWAYS_INLINE void update(const char * data, UInt64 size)
{
/// Avoid UB from `data + 8` arithmetic below when `data == nullptr`.
if (size == 0)

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.

Regardless initial report "/ClickHouse/src/Common/SipHash.h:134:21: runtime error: applying non-zero offset 8 to null pointer" should we just suppress it, it is not a UB in our case, the loop will break early

@groeneai

groeneai commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

@azat you're right that the loop never executes for (nullptr, 0), so it never misbehaves at runtime. The report is the standard-level data + 8 evaluation in the loop condition being UB per [expr.add]/4 even though the result is unused, which UBSan's -fsanitize=pointer-overflow flags.

I'd lean toward keeping the size == 0 guard rather than suppressing, for two reasons:

  1. Cost is effectively zero. For the update<T>(const T &) and other compile-time-size callers, size is a constant so the branch folds away. For the runtime-size string/string_view callers it's one predictable branch that ALWAYS_INLINE keeps in the same frame, dominated by the existing cnt & 7 and loop checks.

  2. A no_sanitize("pointer-overflow") annotation would have to sit on the whole function and would silence pointer-overflow checking for every line of the update loop, masking any genuine pointer bug there in the future. The guard removes the UB instead of hiding the report.

Either way the IntervalKind range check is now the primary fix and closes this report on its own, so the guard isn't load-bearing for STID 3285-3bba; it's just defense-in-depth for any future caller that passes an empty buffer. If you'd still prefer to drop it I'm happy to remove it and rely solely on the deserialization fix.

@azat

azat commented Jun 4, 2026

Copy link
Copy Markdown
Member

@groeneai Ok, then let's do the following:

  • remove sip hash hunk from this PR (since this is a bug fix, and it can be backported)
  • submit this sip hash change as a separate PR and assign it to me

@azat asked for the SipHash defense-in-depth tweak (size==0 short-circuit
plus the gtest) to be split out of this PR so the user-visible bug fix
(out-of-range IntervalKind binary decoding -> INCORRECT_DATA) can be
backported independently.

The SipHash hunk is now PR ClickHouse#106469. This PR keeps only the IntervalKind
range check at the deserialization site plus the regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@azat
azat enabled auto-merge June 4, 2026 13:48
@groeneai

groeneai commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

@azat done.

  • Force-pushed the branch (HEAD 1f6d8cdb9cd) — the SipHash hunk and gtest_sip_hash.cpp are dropped from this PR.
  • This PR now contains only the IntervalKind range check at DataTypesBinaryEncoding.cpp (the user-visible bug fix that should be backportable) plus the 04307_03285_3bba_interval_binary_encoding_invalid_kind regression test.
  • The SipHash size==0 short-circuit and its gtest were re-submitted as SipHash::update: short-circuit on empty input #106469, assigned to you.

PR title and body updated to reflect the IntervalKind-only scope.

The format spec table in `src/DataTypes/DataTypesBinaryEncoding.h` listed
`Year` as `0x1A`, but the canonical value in `IntervalKind::Kind` is `0x0A`,
and `decodeDataType` now rejects any byte outside `0x00..0x0A`. Update the
spec so producers writing the `Interval` binary encoding aren't told to emit
a byte the decoder will reject.

Caught by clickhouse-gh[bot] inline review on PR ClickHouse#106261.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
auto-merge was automatically disabled June 4, 2026 18:06

Head branch was pushed to by a user without write access

@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.50% +0.10%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.10% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 6/6 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI fully finished on 1bccbb57acc8 (post-split + header doc fixup). Triage:

Check Class Action
CH Inc sync infra Internal mirror status check; not a CI test. Not PR-caused.

146 pass / 1 fail / 0 pending / 19 skipping; the single fail is the infra item above. No PR-caused failures, no new flaky tests to track. AI review APPROVED; @ azat APPROVED at 13:48Z. Ready to merge.

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jun 5, 2026
Merged via the queue into ClickHouse:master with commit 2f8e1f5 Jun 5, 2026
166 checks passed
@clickgapai

clickgapai commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Reject out-of-range IntervalKind during binary type decoding

ClickGap verified: reproduced it with the script below on 26.5; tested 5 version(s) — 4 affected, 1 clean (see Affects).

Reproduction

# PR #106261 — "Reject out-of-range IntervalKind during binary type decoding".
#
# decodeDataType() in src/DataTypes/DataTypesBinaryEncoding.cpp cast a raw UInt8
# byte straight to IntervalKind::Kind with no range check. The valid range is
# 0x00 (Nanosecond) .. 0x0A (Year); any byte in 0x0B..0xFF builds a DataTypeInterval
# with an out-of-range kind. Its getName()/toString() then runs magic_enum on an
# unknown value (empty/null string_view on libcxx), corrupting the type name and
# feeding a null pointer into SipHash::update (UBSan pointer-overflow).
#
# The crafted RowBinaryWithNamesAndTypes header below describes one column named
# "t" whose binary-encoded type is Interval (BinaryTypeIndex 0x22) with kind byte
# 0x0B — the first out-of-range value.
#   bytes: 01 (num_columns=1) 01 (name_len=1) 74 ('t') 22 (Interval) 0b (kind)

printf '\x01\x01\x74\x22\x0b' | clickhouse local \
    --input-format RowBinaryWithNamesAndTypes \
    --input_format_binary_decode_types_in_binary_format=1 \
    -q "select * from table"

# Observed (pre-fix): the out-of-range kind byte 0x0B is accepted and decoding
# proceeds with an invalid IntervalKind, triggering undefined behavior (UBSan
# pointer-overflow in SipHash::update) / a corrupted type name.
# Expected (with fix): rejected with Code 117 INCORRECT_DATA,
# "Unknown IntervalKind during Interval type decoding: 0x0b".

Bisect

  • Bisect not performed — master is already clean (the fix landed there), so there is no caused-by regression boundary to bisect within the supported releases.

Affects

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4, 26.3, 25.8
  • Does NOT reproduce on: master
  • Backport needed: 26.5, 26.4, 26.3, 25.8

Suggested next step

The fix has landed on master; the affected release branches above still need the backport.

Component: comp-data-types
Severity: P2

cc fix PR author: @groeneai


ClickGap · Finding: phase_d_pr106261

@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 5, 2026
maxjustus pushed a commit to maxjustus/ClickHouse that referenced this pull request Jun 8, 2026
`SipHash::update(const char * data, UInt64 size)` evaluates `data + size`
and `data + 8` near the start of the unrolled loop. When `data == nullptr`
and `size == 0`, the loop body never executes (the condition
`nullptr + 8 <= nullptr` is false), but evaluating `data + 8` on a null
pointer with non-zero offset is UB per `[expr.add]/4`. UBSan flags this
under `-fsanitize=pointer-overflow`.

The trigger surfaced via `SerializationInterval::getHash` ->
`SipHash::update(std::string_view sv)` -> `update(sv.data(), sv.size())`
when an out-of-range `IntervalKind` produced an empty `std::string_view`
with `data() == nullptr` from `magic_enum::enum_name` on libcxx
(STID 3285-3bba in the AST fuzzer). The primary fix for that specific
path lives in PR ClickHouse#106261 (range check at the deserialization site).

This change is a narrow precondition for `SipHash::update`: an empty
input is a no-op. `ALWAYS_INLINE` keeps the hot path unchanged for
non-empty inputs and the single zero-size branch folds away for callers
that pass a constant non-zero size. Any future caller that legitimately
hands `SipHash::update` a `(nullptr, 0)` pair (e.g. an empty string_view
from another magic_enum-style source) will be a no-op instead of
re-tripping UBSan.

Adds a small gtest (`gtest_sip_hash.cpp`) that:
1. Verifies updating with an empty std::string_view followed by other
   data and a final empty update does not invoke UB and produces a
   stable digest.
2. Verifies the empty updates are observably no-ops: the digest equals
   what you would get hashing the same payload without the empty
   prefix/suffix updates.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@rienath rienath added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 10, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 10, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 10, 2026
rienath added a commit that referenced this pull request Sep 11, 2026
Backport #106261 to 26.3: Reject out-of-range IntervalKind during binary type decoding
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
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 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.

8 participants