ClickHouse / clickhouse-cpp

C++ client library for ClickHouse
Apache License 2.0
300 stars 154 forks source link

SEGV with unsupported type #384

Open PedroTadim opened 2 weeks ago

PedroTadim commented 2 weeks ago

Compile, link and run this modified example program, while running the input from this file: issue.zip

#include <iostream>
#include <fstream>

#include <clickhouse/client.h>

using namespace clickhouse;

int main()
{
    Client client(ClientOptions().SetHost("localhost"));

    std::ifstream infile("<path to file>");
    std::string line;
    while (std::getline(infile, line))
    {
        try {
            client.Execute(line);
        } catch (const std::exception & e) {
        }
    }
    return 0;
}

A SEGV will happen:

Program received signal SIGSEGV, Segmentation fault.
0x00005555556c2a0c in clickhouse::TypeParser::Parse (this=0x7fffffffbf10, type=0x5555559b87c0) at contribs/clickhouse-cpp/clickhouse/types/type_parser.cpp:186
186                 type_ = open_elements_.top();
(gdb) bt
#0  0x00005555556c2a0c in clickhouse::TypeParser::Parse (this=0x7fffffffbf10, type=0x5555559b87c0) at contribs/clickhouse-cpp/clickhouse/types/type_parser.cpp:186
#1  0x00005555556c330c in clickhouse::ParseTypeName (type_name="es=16, max_dynamic_paths=256))", '\000' <repeats 16 times>, "\200\002\000\001\000\000\000\000\000\000\000 \002\026Array(Nullable(Int64))\\Tuple(Nullable(String), Nulla")
    at contribs/clickhouse-cpp/clickhouse/types/type_parser.cpp:305
#2  0x0000555555650305 in clickhouse::CreateColumnByType (
    type_name="es=16, max_dynamic_paths=256))", '\000' <repeats 16 times>, "\200\002\000\001\000\000\000\000\000\000\000 \002\026Array(Nullable(Int64))\\Tuple(Nullable(String), Nulla", settings=...)
    at contribs/clickhouse-cpp/clickhouse/columns/factory.cpp:268
#3  0x0000555555635184 in clickhouse::Client::Impl::ReadBlock (this=0x5555559b8d80, input=..., block=0x7fffffffc120) at contribs/clickhouse-cpp/clickhouse/client.cpp:639
#4  0x0000555555635642 in clickhouse::Client::Impl::ReceiveData (this=0x5555559b8d80) at contribs/clickhouse-cpp/clickhouse/client.cpp:668
#5  0x00005555556346c1 in clickhouse::Client::Impl::ReceivePacket (this=0x5555559b8d80, server_packet=0x0) at contribs/clickhouse-cpp/clickhouse/client.cpp:451
#6  0x0000555555633672 in clickhouse::Client::Impl::ExecuteQuery (this=0x5555559b8d80, query=...) at contribs/clickhouse-cpp/clickhouse/client.cpp:284
#7  0x0000555555637984 in clickhouse::Client::Execute (this=0x7fffffffcbd0, query=...) at contribs/clickhouse-cpp/clickhouse/client.cpp:1010

A proper error message should be thrown when a type is not supported instead of crashing

Enmk commented 2 weeks ago

Hi @PedroTadim, thank you for a report!

I can't reproduce the crash, what are the versions of the clickhouse-cpp and of the clickhouse server? How did you built the clickhouse-cpp?

PedroTadim commented 2 weeks ago

Hello, I built the latest clickhouse binaries from source with this cmake command:

cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DENABLE_LIBRARIES=1 -DENABLE_TESTS=0 -DENABLE_UTILS=0 -DENABLE_THINLTO=0 -DENABLE_NURAFT=1 -DENABLE_SIMDJSON=1 -DENABLE_JEMALLOC=0 -DENABLE_LIBURING=1 -DENABLE_YAML_CPP=1 -DCMAKE_BUILD_TYPE=Debug -DSANITIZE=address
Enmk commented 2 weeks ago

Ok, latest means master ? hm... is there a reason why you haven't used an pre-existing release (official or alternative) ? Also, what is the clickhouse-cpp version you are using and how did you build it?

I've tested clickhouse-cpp master against clickhouse/clickhouse-server docker images ver 23.8, 24.3, and 24.8 on x86_64 and wasn't able to reproduce the issue

PedroTadim commented 2 weeks ago

I updated the example to read input from the given file

PedroTadim commented 2 weeks ago

I compiled both clickhouse-cpp and clickhouse/clickhouse-server from master on debug

PedroTadim commented 5 days ago

Updated example