This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 45dd031c05b [Fix](function) Support encrypt empty string (#51126)
45dd031c05b is described below
commit 45dd031c05b47ec4e1972259fbc6660036e3b529
Author: zclllyybb <[email protected]>
AuthorDate: Thu May 22 18:06:22 2025 +0800
[Fix](function) Support encrypt empty string (#51126)
---
be/src/vec/functions/function_encryption.cpp | 4 ---
be/test/vec/function/function_string_test.cpp | 28 ++++++++++-----------
.../encryption_digest/test_encryption_function.out | Bin 1175 -> 1403 bytes
.../test_encryption_function.groovy | 7 ++++++
4 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/be/src/vec/functions/function_encryption.cpp
b/be/src/vec/functions/function_encryption.cpp
index f6b3f4ae578..66af2d117c6 100644
--- a/be/src/vec/functions/function_encryption.cpp
+++ b/be/src/vec/functions/function_encryption.cpp
@@ -145,10 +145,6 @@ void execute_result(const char* src_raw, size_t src_size,
const char* key_raw, s
size_t i, EncryptionMode& encryption_mode, const char*
iv_raw, size_t iv_length,
ColumnString::Chars& result_data, ColumnString::Offsets&
result_offset,
NullMap& null_map, const char* aad, size_t aad_length) {
- if (src_size == 0) {
- StringOP::push_null_string(i, result_data, result_offset, null_map);
- return;
- }
auto cipher_len = src_size;
if constexpr (is_encrypt) {
cipher_len += 16;
diff --git a/be/test/vec/function/function_string_test.cpp
b/be/test/vec/function/function_string_test.cpp
index 0ba323bcc90..709780ef6bb 100644
--- a/be/test/vec/function/function_string_test.cpp
+++ b/be/test/vec/function/function_string_test.cpp
@@ -1973,6 +1973,7 @@ TEST(function_string_test, function_sm3sum_test) {
}
TEST(function_string_test, function_aes_encrypt_test) {
+ //FIXME: these tests have no meaning because the result is from themselves.
std::string func_name = "aes_encrypt";
{
InputTypeSet input_types = {PrimitiveType::TYPE_VARCHAR,
PrimitiveType::TYPE_VARCHAR,
@@ -1981,9 +1982,9 @@ TEST(function_string_test, function_aes_encrypt_test) {
const char* mode = "AES_128_ECB";
const char* key = "doris";
const char* src[6] = {"aaaaaa", "bbbbbb", "cccccc", "dddddd",
"eeeeee", ""};
- std::string r[5];
+ std::string r[6];
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 6; i++) {
int cipher_len = strlen(src[i]) + 16;
std::vector<char> p(cipher_len);
@@ -1998,7 +1999,7 @@ TEST(function_string_test, function_aes_encrypt_test) {
{{std::string(src[2]), std::string(key),
std::string(mode)}, r[2]},
{{std::string(src[3]), std::string(key),
std::string(mode)}, r[3]},
{{std::string(src[4]), std::string(key),
std::string(mode)}, r[4]},
- {{std::string(src[5]), std::string(key),
std::string(mode)}, Null()},
+ {{std::string(src[5]), std::string(key),
std::string(mode)}, r[5]},
{{Null(), std::string(key), std::string(mode)},
Null()}};
check_function_all_arg_comb<DataTypeString, true>(func_name,
input_types, data_set);
@@ -2010,9 +2011,9 @@ TEST(function_string_test, function_aes_encrypt_test) {
const char* mode = "AES_256_ECB";
const char* key = "vectorized";
const char* src[6] = {"aaaaaa", "bbbbbb", "cccccc", "dddddd",
"eeeeee", ""};
- std::string r[5];
+ std::string r[6];
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 6; i++) {
int cipher_len = strlen(src[i]) + 16;
std::vector<char> p(cipher_len);
int iv_len = 32;
@@ -2033,8 +2034,7 @@ TEST(function_string_test, function_aes_encrypt_test) {
{{std::string(src[2]), std::string(key), std::string(iv),
std::string(mode)}, r[2]},
{{std::string(src[3]), std::string(key), std::string(iv),
std::string(mode)}, r[3]},
{{std::string(src[4]), std::string(key), std::string(iv),
std::string(mode)}, r[4]},
- {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)},
- Null()},
+ {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)}, r[5]},
{{Null(), std::string(key), std::string(iv),
std::string(mode)}, Null()}};
check_function_all_arg_comb<DataTypeString, true>(func_name,
input_types, data_set);
@@ -2116,9 +2116,9 @@ TEST(function_string_test, function_sm4_encrypt_test) {
const char* iv = "0123456789abcdef";
const char* mode = "SM4_128_ECB";
const char* src[6] = {"aaaaaa", "bbbbbb", "cccccc", "dddddd",
"eeeeee", ""};
- std::string r[5];
+ std::string r[6];
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 6; i++) {
int cipher_len = strlen(src[i]) + 16;
std::vector<char> p(cipher_len);
int iv_len = 32;
@@ -2139,8 +2139,7 @@ TEST(function_string_test, function_sm4_encrypt_test) {
{{std::string(src[2]), std::string(key), std::string(iv),
std::string(mode)}, r[2]},
{{std::string(src[3]), std::string(key), std::string(iv),
std::string(mode)}, r[3]},
{{std::string(src[4]), std::string(key), std::string(iv),
std::string(mode)}, r[4]},
- {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)},
- Null()},
+ {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)}, r[5]},
{{Null(), std::string(key), std::string(iv),
std::string(mode)}, Null()}};
check_function_all_arg_comb<DataTypeString, true>(func_name,
input_types, data_set);
@@ -2154,9 +2153,9 @@ TEST(function_string_test, function_sm4_encrypt_test) {
const char* iv = "0123456789abcdef";
const char* mode = "SM4_128_CTR";
const char* src[6] = {"aaaaaa", "bbbbbb", "cccccc", "dddddd",
"eeeeee", ""};
- std::string r[5];
+ std::string r[6];
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 6; i++) {
int cipher_len = strlen(src[i]) + 16;
std::vector<char> p(cipher_len);
int iv_len = 32;
@@ -2177,8 +2176,7 @@ TEST(function_string_test, function_sm4_encrypt_test) {
{{std::string(src[2]), std::string(key), std::string(iv),
std::string(mode)}, r[2]},
{{std::string(src[3]), std::string(key), std::string(iv),
std::string(mode)}, r[3]},
{{std::string(src[4]), std::string(key), std::string(iv),
std::string(mode)}, r[4]},
- {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)},
- Null()},
+ {{std::string(src[5]), std::string(key), std::string(iv),
std::string(mode)}, r[5]},
{{Null(), std::string(key), std::string(iv),
std::string(mode)}, Null()}};
check_function_all_arg_comb<DataTypeString, true>(func_name,
input_types, data_set);
diff --git
a/regression-test/data/nereids_p0/sql_functions/encryption_digest/test_encryption_function.out
b/regression-test/data/nereids_p0/sql_functions/encryption_digest/test_encryption_function.out
index ec96e6df2b0..c2f229d234b 100644
Binary files
a/regression-test/data/nereids_p0/sql_functions/encryption_digest/test_encryption_function.out
and
b/regression-test/data/nereids_p0/sql_functions/encryption_digest/test_encryption_function.out
differ
diff --git
a/regression-test/suites/nereids_p0/sql_functions/encryption_digest/test_encryption_function.groovy
b/regression-test/suites/nereids_p0/sql_functions/encryption_digest/test_encryption_function.groovy
index f96290faffb..a2a2e4f5618 100644
---
a/regression-test/suites/nereids_p0/sql_functions/encryption_digest/test_encryption_function.groovy
+++
b/regression-test/suites/nereids_p0/sql_functions/encryption_digest/test_encryption_function.groovy
@@ -89,4 +89,11 @@ suite("test_encryption_function") {
// test for const opt branch, only first column is not const
qt_sql_gcm_7 "SELECT id,TO_BASE64(AES_ENCRYPT(plain_txt,
'1234567890abcdef', '123456789012', 'aes_128_gcm', 'Some AAD')) from
aes_encrypt_decrypt_tbl where id=1"
qt_sql_gcm_8 "SELECT AES_DECRYPT(FROM_BASE64(enc_txt), '1234567890abcdef',
'', 'aes_128_gcm', 'Some AAD') from aes_encrypt_decrypt_tbl where id=1"
+
+ sql "unset variable block_encryption_mode;"
+ qt_sql_empty1 "select hex(aes_encrypt('', 'securekey456'));"
+ qt_sql_empty2 "select hex(aes_encrypt(rpad('', 16, ''), 'securekey456'));"
+ qt_sql_empty3 "select hex(aes_encrypt(rpad('', 17, ''), 'securekey456'));"
+ qt_sql_empty4 "select hex(sm4_encrypt('', 'securekey456'));"
+ qt_sql_empty5 "select
sm4_decrypt(unhex('0D56319E329CDA9ABDF5870B9D5ACA57'), 'securekey456');"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]