Skip to content

Fix potential Divide by Zero panic#1665

Merged
kavirajk merged 6 commits intoClickHouse:mainfrom
kavirajk:Infowatch/main
Sep 19, 2025
Merged

Fix potential Divide by Zero panic#1665
kavirajk merged 6 commits intoClickHouse:mainfrom
kavirajk:Infowatch/main

Conversation

@kavirajk
Copy link
Copy Markdown
Contributor

Summary

This is based on existing #1643

Preserved the original author's commit. Just addressed the remark on top of it.

Checklist

Delete items not relevant to your PR:

artemseleznev and others added 2 commits September 3, 2025 10:10
The Svace static analyzer (https://www.ispras.ru/en/technologies/svace/) flagged this code as suspicious: it could lead to a panic (division by zero) when data is empty.
@kavirajk
Copy link
Copy Markdown
Contributor Author

I'm figuring out a way to test this edge case via existing tests.

This makes sure any internal state corruption leads to FixedString(0)
wouldn't panic when trying to append value to the column.

This is just there for defensive purpose. Originally you cannot create
such column FixedString(0) because Clickhouse server already rejects
such columns with zero size

Signed-off-by: Kaviraj <[email protected]>
@kavirajk
Copy link
Copy Markdown
Contributor Author

kavirajk commented Sep 19, 2025

Ok. I think it's almost always not possible to reach a state with FixedString with size 0. Because, when you try to create such column the ClickHouse server doesn't let you to do it (Both on Native and HTTP interfaces).

FixedString data type family must have a number (positive integer) as its argument.

Also given the column.FixedString even though public type, one cannot create those types correctly from integrations tests because it's members are private

This patch is still valid to make sure we don't panic in case internal state corruption. So locking this behavior via unit test case only

@kavirajk kavirajk merged commit 12088fe into ClickHouse:main Sep 19, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants