Merge pull request #68105 from JackyWoo/fix_msan_caused_by_incorrect_datetime_str

Fix MSAN issue caused by incorrect date format.
This commit is contained in:
Yarik Briukhovetskyi 2024-08-21 18:06:20 +00:00 committed by GitHub
commit b8027e5566
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 76 additions and 6 deletions

View File

@ -1489,10 +1489,8 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D
size_t size = buf.read(s_pos, remaining_date_size);
if (size != remaining_date_size)
{
s_pos[size] = 0;
if constexpr (throw_exception)
throw Exception(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot parse DateTime {}", s);
throw Exception(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot parse DateTime {}", std::string_view(s, already_read_length + size));
else
return false;
}
@ -1522,10 +1520,8 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D
if (size != time_broken_down_length)
{
s_pos[size] = 0;
if constexpr (throw_exception)
throw Exception(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot parse time component of DateTime {}", s);
throw Exception(ErrorCodes::CANNOT_PARSE_DATETIME, "Cannot parse time component of DateTime {}", std::string_view(s, size));
else
return false;
}

View File

@ -0,0 +1,11 @@
<clickhouse>
<remote_servers>
<test_cluster>
<shard>
<replica>
<host>node</host>
</replica>
</shard>
</test_cluster>
</remote_servers>
</clickhouse>

View File

@ -0,0 +1,9 @@
<clickhouse>
<logger>
<level>information</level>
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>10</count>
</logger>
</clickhouse>

View File

@ -0,0 +1,54 @@
import logging
import pytest
from helpers.cluster import ClickHouseCluster
@pytest.fixture(scope="module")
def cluster():
try:
cluster = ClickHouseCluster(__file__)
cluster.add_instance(
"node",
main_configs=[
"configs/config.d/cluster.xml",
],
)
logging.info("Starting cluster...")
cluster.start()
logging.info("Cluster started")
node = cluster.instances["node"]
node.query(
"""
CREATE TABLE tab
(
a DateTime,
pk String
) Engine = MergeTree() ORDER BY pk;
"""
)
yield cluster
finally:
cluster.shutdown()
def test_incorrect_datetime_format(cluster):
"""
Test for an MSan issue which is caused by parsing incorrect datetime string
"""
node = cluster.instances["node"]
res = node.query("SELECT count(*) FROM tab WHERE a = '2024-08-06 09:58:09'").strip()
assert res == "0"
error = node.query_and_get_error(
"SELECT count(*) FROM tab WHERE a = '2024-08-06 09:58:0'"
).strip()
assert "Cannot parse time component of DateTime 09:58:0" in error
error = node.query_and_get_error(
"SELECT count(*) FROM tab WHERE a = '2024-08-0 09:58:09'"
).strip()
assert "Cannot convert string '2024-08-0 09:58:09' to type DateTime" in error