From 15da99477e0e286adacac1b8e7cc065573d04b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 17 Jan 2022 09:12:14 +0200 Subject: [PATCH] MDEV-27519 CRC32() upon Columnstore table returns a wrong value Func_crc32::getIntVal(): Support the 2-ary CRC32() variant (MDEV-27208). Also, do not assume that the string contains no NUL bytes. --- utils/funcexp/func_crc32.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/utils/funcexp/func_crc32.cpp b/utils/funcexp/func_crc32.cpp index c749331f7..8d4550abe 100644 --- a/utils/funcexp/func_crc32.cpp +++ b/utils/funcexp/func_crc32.cpp @@ -50,8 +50,23 @@ int64_t Func_crc32::getIntVal(rowgroup::Row& row, bool& isNull, CalpontSystemCatalog::ColType& ct) { - const string& val = parm[0]->data()->getStrVal(row, isNull); - return (int64_t) crc32(0L, (unsigned char*)val.c_str(), strlen(val.c_str())); + unsigned crc; + switch (parm.size()) { + default: + isNull = true; + return 0; + case 1: + crc = 0; + break; + case 2: + crc = static_cast(parm[0]->data()->getIntVal(row, isNull)); + if (isNull) + return 0; + } + const string& b = parm[parm.size() - 1]->data()->getStrVal(row, isNull); + if (isNull) + return 0; + return crc32(crc, reinterpret_cast(b.data()), b.size()); }