Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #51804 to 23.4: Fix reading from empty column in parseSipHashKey #51939

Merged
merged 1 commit into from Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Functions/FunctionsHashing.h
Expand Up @@ -81,7 +81,7 @@ namespace impl

static SipHashKey parseSipHashKey(const ColumnWithTypeAndName & key)
{
SipHashKey ret;
SipHashKey ret{};

const auto * tuple = checkAndGetColumn<ColumnTuple>(key.column.get());
if (!tuple)
Expand All @@ -90,6 +90,9 @@ namespace impl
if (tuple->tupleSize() != 2)
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "wrong tuple size: key must be a tuple of 2 UInt64");

if (tuple->empty())
return ret;

if (const auto * key0col = checkAndGetColumn<ColumnUInt64>(&(tuple->getColumn(0))))
ret.key0 = key0col->get64(0);
else
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02790_keyed_hash_bug.reference
@@ -0,0 +1 @@
16324913028386710556
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/02790_keyed_hash_bug.sql
@@ -0,0 +1,2 @@
--- previously caused MemorySanitizer: use-of-uninitialized-value, because we tried to read hash key from empty tuple column during interpretation
SELECT sipHash64Keyed((1111111111111111111, toUInt64(222222222222223))) group by toUInt64(222222222222223);