Skip to content

Do not recurse per empty block in the hadoop-snappy reader - #116994

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-hadoop-snappy-empty-block-recursion
Sep 4, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-hadoop-snappy-empty-block-recursion

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Closes: https://github.com/ClickHouse/clickhouse-private/issues/71249

A hadoop-snappy block that declares zero uncompressed bytes decodes to nothing, and HadoopSnappyReadBuffer::nextImpl returned true for it with an empty working_buffer. ReadBuffer::next calls itself in that case, so a stream of such blocks consumed one stack frame each and could exhaust the stack in builds where the compiler does not turn the self-call into a jump.

Keep decoding until there is output or the input ends, the same way SnappyFramedReadBuffer already skips zero-length chunks.

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

Fixed a stack overflow when reading hadoop-snappy data containing many blocks that decode to nothing.


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

Version info

  • Merged into: 26.9.1.694 (included in 26.9 and later)
  • Backported to: 26.8.3.36, 26.7.7.26, 26.6.5.51, 26.3.31.10

A hadoop-snappy block that declares zero uncompressed bytes decodes to nothing,
and `HadoopSnappyReadBuffer::nextImpl` returned `true` for it with an empty
`working_buffer`. `ReadBuffer::next` calls itself in that case, so a stream of
such blocks consumed one stack frame each and could exhaust the stack in builds
where the compiler does not turn the self-call into a jump.

Keep decoding until there is output or the input ends, the same way
`SnappyFramedReadBuffer` already skips zero-length chunks.
@alexey-milovidov alexey-milovidov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f65dc62]

Summary: ✅


AI Review

Summary

This PR fixes HadoopSnappyReadBuffer::nextImpl so that zero-output hadoop-snappy blocks are skipped inside the reader instead of being surfaced as true with an empty working_buffer, which is the path that let ReadBuffer::next recurse until the stack was exhausted. The control-flow change is consistent with the existing ReadBuffer contract and the sibling SnappyFramedReadBuffer behavior, and the added shell test exercises the snappy path used by file() and INTO OUTFILE. I did not find an unresolved correctness, safety, or PR-metadata issue in the current diff.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit f65dc62.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.00% 81.00% +0.00%

Changed lines: Changed C/C++ lines covered: 25/30 (83.33%) · Uncovered code

Full report · Diff report

`decoder->reset()` is ambiguous between resetting the decoder and resetting the
pointer that holds it, which `readability-ambiguous-smartptr-reset-call` rejects;
spell it through the reference, as the code did before.

Also state in the test what its signal is: the fix changes nothing but the
recursion, so the crash is what the test observes, and that only happens in the
builds that keep the self-call in `ReadBuffer::next`.
@clickhouse-gh

clickhouse-gh Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f65dc6249 with master 0ee60bc06 (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, 5 s compile time in total, 7 of them have a recent master baseline.

Job report

@thevar1able thevar1able self-assigned this Aug 31, 2026

@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 added this pull request to the merge queue Sep 4, 2026
Merged via the queue into master with commit bb1a20e Sep 4, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-hadoop-snappy-empty-block-recursion branch September 4, 2026 11:52
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 4, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 4, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 4, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 4, 2026
Backport #116994 to 26.7: Do not recurse per empty block in the hadoop-snappy reader
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 4, 2026
Backport #116994 to 26.8: Do not recurse per empty block in the hadoop-snappy reader
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #116994 to 26.6: Do not recurse per empty block in the hadoop-snappy reader
alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
Backport #116994 to 26.3: Do not recurse per empty block in the hadoop-snappy reader
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
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.

5 participants