Skip to content

Commit 4cc0b51

Browse files
richardc-dbdongjoon-hyun
authored andcommitted
[SPARK-53806][SQL] Allow empty input on AES decrypt to have error class
### What changes were proposed in this pull request? also catch IllegalArgumentException for AES encrypt/decrypt expressions ### Why are the changes needed? previously, if empty input is given to AES decrypt, it would return the error ``` IllegalArgumentException: Invalid buffer arguments ``` Now, with this change, ``` SparkRuntimeException: [INVALID_PARAMETER_VALUE.AES_KEY] The value of parameter(s) `expr`, `key` in `aes_encrypt`/`aes_decrypt` is invalid: detail message: Invalid buffer arguments ``` ### Does this PR introduce _any_ user-facing change? yes - see above. Error message change ### How was this patch tested? added UT ### Was this patch authored or co-authored using generative AI tooling? no Closes #52523 from richardc-db/fix_error_class_in_aes_decrypt_empty_input. Authored-by: Richard Chen <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent b83d701 commit 4cc0b51

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/ExpressionImplUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private static byte[] aesInternal(
274274
return cipher.doFinal(input, 0, input.length);
275275
}
276276
}
277-
} catch (GeneralSecurityException e) {
277+
} catch (GeneralSecurityException | IllegalArgumentException e) {
278278
throw QueryExecutionErrors.aesCryptoError(e.getMessage());
279279
}
280280
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionImplUtilsSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ class ExpressionImplUtilsSuite extends SparkFunSuite {
325325
"functionName" -> "`aes_encrypt`/`aes_decrypt`",
326326
"detailMessage" -> "Tag mismatch[!]?"
327327
)
328+
),
329+
// Empty input
330+
TestCase(
331+
"Spark",
332+
"abcdefghijklmnop12345678ABCDEFGH",
333+
"",
334+
"GCM",
335+
expectedErrorClassOpt = Some("INVALID_PARAMETER_VALUE.AES_CRYPTO_ERROR"),
336+
errorParamsMap = Map(
337+
"parameter" -> "`expr`, `key`",
338+
"functionName" -> "`aes_encrypt`/`aes_decrypt`",
339+
"detailMessage" -> "Invalid buffer arguments"
340+
)
328341
)
329342
)
330343

0 commit comments

Comments
 (0)