[client-v2] A String bound to an {name:Identifier} parameter is escaped, so a name with a backslash (or tab/newline) addresses the wrong identifier
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
Hướng nghiên cứu
Start in client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java around lines 271-287, where escapeStringParameter handles every CharSequence, then follow the call from Client.java (~line 2005) to see where the SQL text and the parameter map are both still in scope. Because the placeholder type is only in the SQL, the fix has to scan sqlQuery for {name:Type} before formatting, and the same path feeds the queryRecords/queryAll overloads. Run the supplied TestNG reproduction against a local server on port 8123; done means the alias equals a\b and the JSON subcolumn read returns 3, while {name:String} escaping still applies.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
client-v2 escapes every scalar String query parameter the same way, whatever type the placeholder declares. DataTypeConverter.convertParameterToString sends a CharSequence through escapeStringParameter, which doubles a backslash and turns a tab/newline into \t/\n:
That is correct for {name:String}, because the server reads the value with deserializeTextEscaped and removes the escapes. It is wrong for {name:Identifier}: the server takes that value as it is and does not unescape it, so the extra backslash becomes part of the identifier.
Confirmed against the server with plain HTTP (26.10.4.207):
param_name=a\b SELECT 1 AS {name:Identifier} -> column name a\b (correct)
param_name=a\\b SELECT 1 AS {name:Identifier} -> column name a\\b (extra backslash)
param_name=a\b SELECT {name:String} -> value a<BS>b (needs the escape)
param_name=a\\b SELECT {name:String} -> value a\b (correct)
So the client must not escape a value bound to an Identifier placeholder. There is no error: an alias comes back with an extra backslash, and a JSON subcolumn read returns an empty/NULL value because that key does not exist.
Scope: only backslash, tab and newline are affected, because escapeStringParameter escapes only those three. A backtick or a single quote is passed through unchanged and works correctly (unlike clickhouse-connect, where every string parameter is quoted/escaped).
The escaping was added in #2962.
ClickHouse server version
26.10.4.207 (official build), reached over HTTP at localhost:8123. Client built from main (0.12.0-rc1-SNAPSHOT).
Reproduction
TestNG test in client-v2, run against a local server:
package com.clickhouse.client;
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.query.GenericRecord;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;
public class IdentifierParamTest {
@Test
public void identifierParamWithBackslashNamesTheWrongIdentifier() throws Exception {
try (Client client = new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default")
.setPassword("")
.compressServerResponse(false)
.build()) {
String name = "a\\b"; // the two-character name a-backslash-b
List<GenericRecord> aliased = client.queryAll("SELECT 1 AS {name:Identifier}",
Collections.singletonMap("name", (Object) name), null);
assertEquals(aliased.get(0).getSchema().getColumns().get(0).getColumnName(), name);
client.execute("DROP TABLE IF EXISTS default.repro_ident").get();
client.execute("CREATE TABLE default.repro_ident (attributes JSON) "
+ "ENGINE = MergeTree ORDER BY tuple()").get();
client.execute("INSERT INTO default.repro_ident FORMAT JSONEachRow "
+ "{\"attributes\": {\"a\\\\b\": 3}}").get();
List<GenericRecord> read = client.queryAll(
"SELECT toString(attributes.{name:Identifier}) AS v FROM default.repro_ident",
Collections.singletonMap("name", (Object) name), null);
assertEquals(read.get(0).getString(1), "3");
client.execute("DROP TABLE default.repro_ident").get();
}
}
}
Expected: both assertions pass - the alias is a\b and the JSON subcolumn read returns 3.
Actual (observed): the first assertion fails. The alias comes back as a\\b (two backslashes), and the JSON read returns an empty value because the key a\\b does not exist.
Full matrix printed by the same code for plain, a`b, a\b and it's (strings shown with backslashes doubled):
passed="plain" alias="plain" match=true read -> "1"
passed="a`b" alias="a`b" match=true read -> "2"
passed="a\\b" alias="a\\\\b" match=false read -> "" <-- wrong
passed="it's" alias="it's" match=true read -> "4"
A tab or a newline in the name fails the same way (\t/\n end up literally in the identifier).
Suggested fix
Client.query(...) formats parameters without looking at the SQL, so the placeholder type is not known at that point:
client-v2/src/main/java/com/clickhouse/client/api/Client.java(~line 2005) - formats every entry withDataTypeConverter.INSTANCE.convertParameterToString(value)client-v2/src/main/java/com/clickhouse/client/api/internal/DataTypeConverter.java(~line 271) - escapes everyCharSequence
A fix would scan sqlQuery for the {name:Type} placeholders and pass a String bound to an Identifier placeholder through unchanged (same approach as the one proposed for clickhouse-connect). The same applies to the queryRecords/queryAll overloads that take a parameter map.
Link
Reported for the Python client in https://github.com/ClickHouse/clickhouse-connect/issues/1243
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 657
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 36
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc performance queries sql-parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api-diagnostics bug client jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3439 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ClickHouse/clickhouse-java
Issue tương tự
-
[BUG] Nightly Build JDK 17: latest-frameworks job red since 2026-11-28 — quarkiverse-langchain4j 2.0.0 pins Quarkus 4.0.0, which requires Java 21Có thể đã có người làm @uhhgxg đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
langchain4j/langchain4j#7344 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cristianEncarnacion/ferroreport#149 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
quelea-projection/Quelea#749 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100