Skip to content

Fix UBSan reports in master: unsigned wraparound in offsets[row - 1] of the JSON conversion - #133910

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-ubsan-json-conversion-offsets
Nov 24, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-ubsan-json-conversion-offsets

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Related: #107866
Related: #120906

FunctionsConversion.cpp reads offsets[row - 1] with row == 0 in six places added in #107866. row is a size_t, so the index wraps around before it reaches the ssize_t parameter of PODArray::operator[], and the unsigned-integer-overflow check of UBSan, enabled in #120906 on the same day, reports it and stops the server:

src/Functions/FunctionsConversion.cpp:2929:73: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')
    #0 newLeafTypedPathsNeedFormatParse src/Functions/FunctionsConversion.cpp:2929:73
    #1 DB::detail::(anonymous namespace)::convertObjectColumns src/Functions/FunctionsConversion.cpp:3343:9

Since the merge of #107866 (e903e8848f03, 2026-11-23), the asan_ubsan stateless tests on master fail with UndefinedBehaviorSanitizer: undefined behavior (STID: 0993-9a84) and Server died: 23 failures on 11 master commits within the first 2.5 hours, and the same in pull requests that merged or are tested with the new master. The first report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=e903e8848f033e59d209c21e5258e617157ba884&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

The fix uses the signed form offsets[static_cast<ssize_t>(row) - 1], as the rest of the code does. The existing tests of the JSON conversion cover it under UBSan. I did not find an open issue for this report.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.345-master (included in 26.12 and later)

`FunctionsConversion.cpp` read `offsets[row - 1]` with `row == 0` in six places
added in #107866. `row` is a `size_t`,
so the index wraps around before it reaches the `ssize_t` parameter of
`PODArray::operator[]`, and the `unsigned-integer-overflow` check of UBSan, enabled
in #120906, reports it and stops the server:

    src/Functions/FunctionsConversion.cpp:2929:73: runtime error: unsigned integer overflow:
    0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')
        #0 newLeafTypedPathsNeedFormatParse src/Functions/FunctionsConversion.cpp:2929:73
        #1 DB::detail::(anonymous namespace)::convertObjectColumns src/Functions/FunctionsConversion.cpp:3343:9

Since the merge of that pull request, the `asan_ubsan` stateless tests on master fail
with `UndefinedBehaviorSanitizer: undefined behavior (STID: 0993-9a84)` and `Server died`:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=e903e8848f033e59d209c21e5258e617157ba884&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29

Use the signed form `offsets[static_cast<ssize_t>(row) - 1]`, as the rest of the code does.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a2743a]

Summary: ✅


AI Review

Summary

PR #133910 fixes six unsigned offset underflows in JSON conversions by casting row to ssize_t before subtracting one. Reviewed head 4a2743adbd81f35bdd8b02ee922fe0927f36f52d: no actionable findings. Existing conversion tests cover the affected paths, including 05816_json_conversion_optimized_matches_format_parse_2, which passed in Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 23, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... label Nov 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a2743adb with master 76ecf3a22 (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... pr-ci 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.

2 participants