From 6630f7bb670a4e69e6fb78329c8dcb281fd3f923 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 4 Sep 2024 11:32:08 +0200 Subject: [PATCH] GH-43946: [C++][Parquet] Guard against use of decryptor/encryptor after wipeout --- cpp/src/parquet/encryption/encryption_internal.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cpp/src/parquet/encryption/encryption_internal.cc b/cpp/src/parquet/encryption/encryption_internal.cc index a0d9367b619c6..05ec88bb1d9cf 100644 --- a/cpp/src/parquet/encryption/encryption_internal.cc +++ b/cpp/src/parquet/encryption/encryption_internal.cc @@ -29,6 +29,8 @@ #include #include +#include "arrow/util/logging.h" + #include "parquet/encryption/openssl_internal.h" #include "parquet/exception.h" @@ -156,6 +158,8 @@ AesEncryptor::AesEncryptorImpl::AesEncryptorImpl(ParquetCipher::type alg_id, int32_t AesEncryptor::AesEncryptorImpl::SignedFooterEncrypt( span footer, span key, span aad, span nonce, span encrypted_footer) { + ARROW_CHECK_NE(ctx_, nullptr) << "AesEncryptor was wiped out"; + if (static_cast(key_length_) != key.size()) { std::stringstream ss; ss << "Wrong key length " << key.size() << ". Should be " << key_length_; @@ -180,6 +184,8 @@ int32_t AesEncryptor::AesEncryptorImpl::Encrypt(span plaintext, span key, span aad, span ciphertext) { + ARROW_CHECK_NE(ctx_, nullptr) << "AesEncryptor was wiped out"; + if (static_cast(key_length_) != key.size()) { std::stringstream ss; ss << "Wrong key length " << key.size() << ". Should be " << key_length_; @@ -714,6 +720,8 @@ int32_t AesDecryptor::AesDecryptorImpl::Decrypt(span ciphertext, span key, span aad, span plaintext) { + ARROW_CHECK_NE(ctx_, nullptr) << "AesDecryptor was wiped out"; + if (static_cast(key_length_) != key.size()) { std::stringstream ss; ss << "Wrong key length " << key.size() << ". Should be " << key_length_; @@ -806,4 +814,7 @@ void RandBytes(unsigned char* buf, size_t num) { void EnsureBackendInitialized() { openssl::EnsureInitialized(); } +#undef ENCRYPT_INIT +#undef DECRYPT_INIT + } // namespace parquet::encryption