nikepan / clickhouse-bulk

Collects many small inserts to ClickHouse and send in big inserts
Apache License 2.0
474 stars 87 forks source link

Incorrect ParseQuery logick #57

Closed valodzka closed 1 year ago

valodzka commented 1 year ago

ParseQuery in in collector.go incorrectly handles case when there are params before and after query https://github.com/nikepan/clickhouse-bulk/blob/b34e73cdafdd3682fe5e3dd193a0f977f7121ad1/collector.go#L315

It might cause incorrect results or panic: runtime error: slice bounds out of range depending on params length.

Instead of

if eoq >= 0 {
            q = queryString[i+6 : eoq+6]
            params = queryString[:i] + queryString[eoq+7:]
}

It should be:

if eoq >= 0 {
            q = queryString[i+6 : i+eoq+6]
            params = queryString[:i] + queryString[i+eoq+7:]
}

Example of problematic string: queryString = "a=11111111111111111111111111111&query=insert into x format fmt&a=1"