Skip to content

Server crash in ProtobufReader::endMessage when processing truncated Protobuf INSERT with error skipping enabled #106904

Closed

Description

@atsarevskiy

Company or project name

AWS

Describe what's wrong

A null pointer dereference in ProtobufRowInputFormat::syncAfterError() crashes the ClickHouse server when a Protobuf INSERT encounters malformed/truncated data and input_format_allow_errors_num > 0. Once crashed, the server refuses all new connections (including /ping) because isCrashed() returns true.

The problem is in this code:

 void ProtobufRowInputFormat::syncAfterError()
 {
      reader->endMessage(true);  // reader is null here → SIGSEGV
 }

Stack trace:

Signal: Segmentation fault (11)
2026.06.09 22:29:10.679561 [ 1140 ] {} <Fatal> BaseDaemon: Address: 0x18. Access: <not available>. Address not mapped to object.
2026.06.09 22:29:10.679567 [ 1140 ] {} <Fatal> BaseDaemon: Stack trace: ....
2026.06.09 22:29:10.679616 [ 1140 ] {} <Fatal> BaseDaemon: 2. DB::ProtobufReader::endMessage(bool) @ 0x000000001a72ed71
2026.06.09 22:29:10.679649 [ 1140 ] {} <Fatal> BaseDaemon: 3. DB::IRowInputFormat::read() @ 0x000000001a5398b4
2026.06.09 22:29:10.679680 [ 1140 ] {} <Fatal> BaseDaemon: 4. DB::IInputFormat::generate() @ 0x000000001a4d0fe0
2026.06.09 22:29:10.679712 [ 1140 ] {} <Fatal> BaseDaemon: 5. DB::ISource::tryGenerate() @ 0x000000001a4a7acc
2026.06.09 22:29:10.679748 [ 1140 ] {} <Fatal> BaseDaemon: 6. DB::ISource::work() @ 0x000000001a4a7660
2026.06.09 22:29:10.679797 [ 1140 ] {} <Fatal> BaseDaemon: 7. DB::ExecutionThreadContext::executeTask() @ 0x000000001a4c1a94
2026.06.09 22:29:10.679844 [ 1140 ] {} <Fatal> BaseDaemon: 8. DB::PipelineExecutor::executeStepImpl(unsigned long, DB::IAcquiredSlot*, std::atomic<bool>*) @ 0x000000001a4b4dc8
2026.06.09 22:29:10.679885 [ 1140 ] {} <Fatal> BaseDaemon: 9. DB::PipelineExecutor::executeStep(std::atomic<bool>*) @ 0x000000001a4b3ce8
2026.06.09 22:29:10.679927 [ 1140 ] {} <Fatal> BaseDaemon: 10. DB::PullingPipelineExecutor::pull(DB::Chunk&) @ 0x000000001a4cb750
2026.06.09 22:29:10.679969 [ 1140 ] {} <Fatal> BaseDaemon: 11. DB::PullingPipelineExecutor::pull(DB::Block&) @ 0x000000001a4cba20

Does it reproduce on the most recent release?

Yes

How to reproduce

Any INSERT with truncated Protobuf data where:

  1. The format is Protobuf with length-delimited messages
  2. A fixed-size field (fixed32/fixed64/double/float) is truncated mid-read
  3. input_format_allow_errors_num > 0 (or input_format_allow_errors_ratio > 0)

Expected behavior

Clickhouse server shouldn't crash in this situation

Error message and/or stacktrace

Signal: Segmentation fault (11)
2026.06.09 22:29:10.679561 [ 1140 ] {} <Fatal> BaseDaemon: Address: 0x18. Access: <not available>. Address not mapped to object.
2026.06.09 22:29:10.679567 [ 1140 ] {} <Fatal> BaseDaemon: Stack trace: ....
2026.06.09 22:29:10.679616 [ 1140 ] {} <Fatal> BaseDaemon: 2. DB::ProtobufReader::endMessage(bool) @ 0x000000001a72ed71
2026.06.09 22:29:10.679649 [ 1140 ] {} <Fatal> BaseDaemon: 3. DB::IRowInputFormat::read() @ 0x000000001a5398b4
2026.06.09 22:29:10.679680 [ 1140 ] {} <Fatal> BaseDaemon: 4. DB::IInputFormat::generate() @ 0x000000001a4d0fe0
2026.06.09 22:29:10.679712 [ 1140 ] {} <Fatal> BaseDaemon: 5. DB::ISource::tryGenerate() @ 0x000000001a4a7acc
2026.06.09 22:29:10.679748 [ 1140 ] {} <Fatal> BaseDaemon: 6. DB::ISource::work() @ 0x000000001a4a7660
2026.06.09 22:29:10.679797 [ 1140 ] {} <Fatal> BaseDaemon: 7. DB::ExecutionThreadContext::executeTask() @ 0x000000001a4c1a94
2026.06.09 22:29:10.679844 [ 1140 ] {} <Fatal> BaseDaemon: 8. DB::PipelineExecutor::executeStepImpl(unsigned long, DB::IAcquiredSlot*, std::atomic<bool>*) @ 0x000000001a4b4dc8
2026.06.09 22:29:10.679885 [ 1140 ] {} <Fatal> BaseDaemon: 9. DB::PipelineExecutor::executeStep(std::atomic<bool>*) @ 0x000000001a4b3ce8
2026.06.09 22:29:10.679927 [ 1140 ] {} <Fatal> BaseDaemon: 10. DB::PullingPipelineExecutor::pull(DB::Chunk&) @ 0x000000001a4cb750
2026.06.09 22:29:10.679969 [ 1140 ] {} <Fatal> BaseDaemon: 11. DB::PullingPipelineExecutor::pull(DB::Block&) @ 0x000000001a4cba20

Related issues and pull requests

No response

Additional context

No response

Version info

Activity

  1. added
    potential bug
    on Jun 10, 2026
  2. added 7 commits that reference this issue on Jun 10, 2026
    037bb1b
    2a962d5
    7df62b9
    b9aa27f
    68074cd
    f0d4172
    cda0490
  3. clickgapai commented on Jun 13, 2026

    @clickgapai
    Contributor

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

    TL;DR

    Server crash in ProtobufReader::endMessage when processing truncated Protobuf INSERT with error skipping enabled

    ClickGap verified: reproduced it with the script below on master; tested 5 version(s) — 5 affected, 0 clean (see Affects); confirmed it predates the oldest available release (pre-existing).

    Reproduction

    Shell reproducer — run against a local ClickHouse build (bash <script> <clickhouse-binary>); requires the referenced test fixtures from the repo.

    # Server/process crash (SIGSEGV) in ProtobufRowInputFormat::syncAfterError().
    # A length-delimited Protobuf INSERT whose fixed64 (double) field is truncated
    # mid-read raises CANNOT_READ_ALL_DATA. With error skipping enabled
    # (input_format_allow_errors_num>0), IRowInputFormat::read() calls
    # syncAfterError() -> reader->endMessage(true). But readRow()'s catch handler
    # already ran destroyReaderAndSerializer(), leaving reader=nullptr, so
    # endMessage dereferences a null pointer -> SIGSEGV (Address 0x18).
    
    # 1. Protobuf schema with a single double field:
    cat > repro.proto <<'EOF'
    syntax = "proto3";
    message Msg {
      double x = 1;
    }
    EOF
    
    # 2. A length-delimited Protobuf message with the fixed64 field truncated mid-read:
    #      0x09            -> varint length prefix = 9 (body claims 9 bytes)
    #      0x09            -> field tag: field #1, wire type 1 (BITS64 = fixed64/double)
    #      0x01 0x02 0x03  -> only 3 of the 8 bytes of the double, then EOF
    printf '\x09\x09\x01\x02\x03' > data.bin
    
    # 3. INSERT with error skipping enabled -> crash:
    clickhouse local \
      --input_format_allow_errors_num=1 \
      --format_schema="repro:Msg" \
      --query "CREATE TABLE t (x Float64) ENGINE=Memory; INSERT INTO t FROM INFILE 'data.bin' FORMAT Protobuf; SELECT count() FROM t;"

    Bisect

    • Present since at least v25.7.8.71 — reproduces on every release line tested down to there; the introducer predates the oldest release with a downloadable binary, so a single commit isn't pinnable from release binaries (not a recent regression).

    Affects

    • Reproduces on: master, 26.5, 26.4, 26.3, 25.8

    Suggested next step

    Manual triage of the comp-formats path is needed. The reproducer above should be a fast first check.

    Component: comp-formats
    Severity: P2


    ClickGap · Finding: h_issue_106904

  4. self-assigned this
    on Jun 15, 2026
  5. atsarevskiy commented on Jun 15, 2026

    @atsarevskiy
    ContributorAuthor

    I have sent a fix #106905

  6. Avogar commented on Jun 15, 2026

    @Avogar
    Member

    Thanks! I will take a look

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

Metadata

Metadata

Assignees

Labels

potential bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions