Skip to content

Do not expose uninitialized memory in query results - #115704

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-uninitialized-memory-in-results
Aug 22, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-uninitialized-memory-in-results

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Two places where uninitialized or stale memory could end up in the result of a query:

  • The buffer for a binary string literal (b'...') is allocated for the worst case, ceil(bits / 8)
    bytes, but when the number of bits is not a multiple of eight fewer bytes are written, and the
    result was built from the size of the buffer rather than from the number of bytes written. So
    SELECT hex(b'000000001') returned 01 followed by a byte of uninitialized memory.
  • LZ4::decompress returned success without writing anything when the compressed block was empty
    while the caller expected a non-empty result, and the caller then handed out whatever was in the
    destination buffer.

A third one, formatRowNoNewline stepping the position of a shared buffer back into the previous
row, was in this pull request initially; it was fixed separately in
#115669, which is already in master, so this branch
now carries the version from master.

Related: #115669

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Do not return uninitialized memory in the result of a binary string literal whose length is not a multiple of eight, and from the LZ4 decompressor when a compressed block has no body.


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

Version info

  • Merged into: 26.8.1.1909 (included in 26.8 and later)
  • Backported to: 26.7.6.8, 26.6.4.13, 26.5.8.24, 26.3.23.6, 25.8.33.5

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7803723]

Summary: ✅


AI Review

Summary

This PR closes two real uninitialized-memory disclosure paths: binary string literals now build the result from the number of bytes actually decoded, and LZ4 decompression now fails instead of reporting success when the compressed body is empty but the caller expects output. The current branch also adds focused stateless coverage for both regressions, so the fixes and evidence match the stated contract.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 5/6 (83.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7803723fa with master b16561cc8 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 333650598; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.42 MiB 701.40 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

alexey-milovidov and others added 2 commits August 21, 2026 13:57
…emory-in-results

# Conflicts:
#	src/Functions/formatRow.cpp
The compressed block declares a compressed size equal to the size of the
header and a non-zero uncompressed size, so `LZ4::decompress` has nothing
to read from. Before the fix it reported success without writing anything,
and the destination buffer, which is used as the text of the query in this
test, was handed out with whatever it contained. The response to the
request then quoted the leaked bytes back to the client, for example:

    Code: 62. DB::Exception: Syntax error: failed at position 1 (DB): DB::HTTPHandler:.

The checksum of the block is not verified thanks to
`http_native_compression_disable_checksumming_on_decompress`, which makes
it possible to craft such a block from a test.

Co-Authored-By: Claude Fable 5 <[email protected]>

@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

@alexey-milovidov alexey-milovidov self-assigned this Aug 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 22, 2026
Merged via the queue into master with commit 489d8a9 Aug 22, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-uninitialized-memory-in-results branch August 22, 2026 18:42
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 22, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 22, 2026
Backport #115704 to 26.6: Do not expose uninitialized memory in query results
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 22, 2026
Backport #115704 to 26.7: Do not expose uninitialized memory in query results
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 25, 2026
Cherry pick #115704 to 25.8: Do not expose uninitialized memory in query results
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 25, 2026
alexey-milovidov added a commit that referenced this pull request Aug 26, 2026
Backport #115704 to 25.8: Do not expose uninitialized memory in query results
alexey-milovidov added a commit that referenced this pull request Aug 26, 2026
Backport #115704 to 26.5: Do not expose uninitialized memory in query results
alexey-milovidov added a commit that referenced this pull request Aug 26, 2026
Backport #115704 to 26.3: Do not expose uninitialized memory in query results
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
OTHER: binary literal whose length is not a multiple of 8; empty LZ4 block -> wrong (uninitialized memory).
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/115704.PROD263.txt).
Upstream patch unchanged, with its test(s): 05024_binary_string_literal_uninitialized_byte, 05028_lz4_empty_compressed_body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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.

4 participants