Type-name parser (HTTP) accepts unbalanced parentheses: ColumnTypes "Nullable(String" stores NULL rows with no error
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start with ClickHouse.Driver/Types/Grammar/Parser.cs, where Parser.Parse builds the type tree, and inspect the stack operations and end-of-input handling described in the issue. Reproduce the malformed inputs with the public parser and check the HTTP type-name entry points listed in the report. Done means each malformed name raises an ArgumentException naming the input, with no invalid type accepted or null returned.
Written by the indexing model from the issue text.
Description
Describe the bug
The HTTP client's type-name parser does not check that the parentheses of a type name are balanced. The server rejects all of these names with SYNTAX_ERROR, but the client accepts some of them as a different type, and fails on others with an internal exception type.
- A name with an unclosed
(is read as its innermost type:Nullable(StringisString,Array(Int32andMap(String, Int32areInt32. - A name with an extra
)or a top-level,(Nullable(Int32)),Array(Int32),Int64) throwsInvalidOperationException: Stack empty. - A name that ends after
((SimpleAggregateFunction() throwsNullReferenceException.
A misspelled type in InsertOptions.ColumnTypes can store wrong rows with no error. InsertBinaryAsync writes the rows with the wrong type, and the server reads the bytes with the real column type. With ColumnTypes["v"] = "Nullable(String" (one ) missing), two rows "hello" and "world" are stored as 12 NULL rows, and the call returns 2.
The other entry points that parse a caller's type name are ClickHouseDbParameter.ClickHouseType and {name:Type} hints (extra ) or ,: InvalidOperationException before the request), and the public ClickHouse.Driver.Types.Grammar.Parser.Parse. The header of a RowBinaryWithNamesAndTypes response goes through the same parser.
Steps to reproduce
- Create a table with a
Nullable(String)column. - Insert two rows with
InsertBinaryAsync, withInsertOptions.ColumnTypesset toNullable(String(one)missing). - Read the table.
Expected behaviour
The client rejects a malformed type name with an ArgumentException that names the input, as it does for Array[Int32] (ArgumentException: Unknown type: Array[Int32]), and writes nothing. The server rejects these names:
SELECT CAST(NULL, 'Nullable(String')
Code: 62. DB::Exception: Syntax error (data type): failed at position 16 (end of query): (String. Unmatched parentheses: '(' at position 9 is never closed ... (SYNTAX_ERROR)
SELECT CAST(NULL, 'Array(Int32))')
Code: 62. DB::Exception: Syntax error (data type): ... Unmatched parentheses: ')' at position 13 has no matching opening bracket ... (SYNTAX_ERROR)
The TCP client of this repo rejects all of these names with FormatException (ClickHouse.Driver.Tcp/Types/TypeParser.cs:11).
Code example
await client.ExecuteNonQueryAsync("CREATE TABLE t (v Nullable(String)) ENGINE = MergeTree ORDER BY tuple()");
var options = new InsertOptions { ColumnTypes = new Dictionary<string, string> { ["v"] = "Nullable(String" } };
var n = await client.InsertBinaryAsync("t", new[] { "v" }, new[] { new object[] { "hello" }, new object[] { "world" } }, options);
Console.WriteLine(n); // 2, no exception
Console.WriteLine(await client.ExecuteScalarAsync("SELECT count() FROM t")); // 12
Console.WriteLine(await client.ExecuteScalarAsync("SELECT countIf(v IS NULL) FROM t")); // 12
Parser.Parse("Array(Int32").ToString(); // "Int32"
Parser.Parse("Nullable(Int32))"); // InvalidOperationException: Stack empty.
Parser.Parse("SimpleAggregateFunction("); // null
Error log
InsertBinaryAsync, ColumnTypes "Nullable(String", values ["hello","world"] -> returned 2; stored: 12 x NULL
Parser.Parse("Array(Int32") -> Int32
Parser.Parse("Nullable(Int32))") -> InvalidOperationException: Stack empty.
Parser.Parse("SimpleAggregateFunction(") -> null; TypeConverter then throws NullReferenceException
Root cause: Parser.Parse (ClickHouse.Driver/Types/Grammar/Parser.cs) builds the tree on a stack and never checks it. At the end of the input it returns current also when the stack still holds open nodes (line 36). It calls stack.Pop() (line 29) and stack.Peek() (line 43) with no check for an empty stack. It returns null when the input ends after (, and TypeConverter.ExtractTypeName then reads node.Value (ClickHouse.Driver/Types/TypeConverter.cs:250).
The fix is three checks in Parser.Parse.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Configuration
Environment
- Client version:
mainat c58178ed (after 1.7.0) - Language version: C# (latest)
- .NET version: .NET 10 (
net10.0, SDK 11.0.100) - OS: Linux
ClickHouse server
- ClickHouse Server version: 26.11.7.10
Classification: impact: Data integrity · area: Data types & formats (type names, RowBinary)
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-rs#578. Verified against a live server.
- Dominant language
- C#
- Stars
- 102
- Forks
- 31
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/clickhouse-cs
-
bug documentation queries
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#815 ·
Maintainers usually reply within 1 day
-
bug data-types native-format
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-cs#813 ·
Maintainers usually reply within 1 day
-
bug data-types documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#811 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#809 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-cs#804 ·
Maintainers usually reply within 1 day
All issues in ClickHouse/clickhouse-cs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlPossibly taken @alexeyfala claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
danipen/TextMateSharp#145 · 2 comments ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Klyroo/klyroo-dashboard#12 ·
Maintainers usually reply within 1 day
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates onPossibly taken @yadavraj2001 claimed this today. Opendocumentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
juandresrodca/AdminForge#73 · 1 comment ·
Maintainers usually reply within 1 day
-
[辞書] VIVANTOpen要トリアージ 辞書
Difficulty 1/5 Under an hour Newbie friendliness 70/100
Maintainers usually reply within 1 day