Skip to content

Commit

Permalink
apacheGH-43946: [C++][Parquet] Guard against use of decryptor/encrypt…
Browse files Browse the repository at this point in the history
…or after wipeout
  • Loading branch information
pitrou committed Sep 4, 2024
1 parent 170c599 commit 6630f7b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cpp/src/parquet/encryption/encryption_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <string>
#include <vector>

#include "arrow/util/logging.h"

#include "parquet/encryption/openssl_internal.h"
#include "parquet/exception.h"

Expand Down Expand Up @@ -156,6 +158,8 @@ AesEncryptor::AesEncryptorImpl::AesEncryptorImpl(ParquetCipher::type alg_id,
int32_t AesEncryptor::AesEncryptorImpl::SignedFooterEncrypt(
span<const uint8_t> footer, span<const uint8_t> key, span<const uint8_t> aad,
span<const uint8_t> nonce, span<uint8_t> encrypted_footer) {
ARROW_CHECK_NE(ctx_, nullptr) << "AesEncryptor was wiped out";

if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand All @@ -180,6 +184,8 @@ int32_t AesEncryptor::AesEncryptorImpl::Encrypt(span<const uint8_t> plaintext,
span<const uint8_t> key,
span<const uint8_t> aad,
span<uint8_t> ciphertext) {
ARROW_CHECK_NE(ctx_, nullptr) << "AesEncryptor was wiped out";

if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand Down Expand Up @@ -714,6 +720,8 @@ int32_t AesDecryptor::AesDecryptorImpl::Decrypt(span<const uint8_t> ciphertext,
span<const uint8_t> key,
span<const uint8_t> aad,
span<uint8_t> plaintext) {
ARROW_CHECK_NE(ctx_, nullptr) << "AesDecryptor was wiped out";

if (static_cast<size_t>(key_length_) != key.size()) {
std::stringstream ss;
ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
Expand Down Expand Up @@ -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

0 comments on commit 6630f7b

Please sign in to comment.