-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-43946: [C++][Parquet] Guard against use of cleared decryptor/encryptor #43947
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -89,6 +89,12 @@ class AesEncryptor::AesEncryptorImpl { | |||||
} | ||||||
|
||||||
private: | ||||||
void CheckValid() const { | ||||||
if (ctx_ == nullptr) { | ||||||
throw ParquetException("AesEncryptor was wiped out"); | ||||||
} | ||||||
} | ||||||
|
||||||
EVP_CIPHER_CTX* ctx_; | ||||||
int32_t aes_mode_; | ||||||
int32_t key_length_; | ||||||
|
@@ -156,6 +162,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) { | ||||||
CheckValid(); | ||||||
|
||||||
if (static_cast<size_t>(key_length_) != key.size()) { | ||||||
std::stringstream ss; | ||||||
ss << "Wrong key length " << key.size() << ". Should be " << key_length_; | ||||||
|
@@ -180,6 +188,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) { | ||||||
CheckValid(); | ||||||
|
||||||
if (static_cast<size_t>(key_length_) != key.size()) { | ||||||
std::stringstream ss; | ||||||
ss << "Wrong key length " << key.size() << ". Should be " << key_length_; | ||||||
|
@@ -413,6 +423,12 @@ class AesDecryptor::AesDecryptorImpl { | |||||
} | ||||||
|
||||||
private: | ||||||
void CheckValid() const { | ||||||
if (ctx_ == nullptr) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that compilers automatically treated branches that throw an exception to be unlikely, but I can't find a reference. @felipecrv Do you know about that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, judging from https://www.youtube.com/watch?v=T84swS6DCRo (at 29:00), the gcc compiler already uses such a heuristic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CheckValid should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point @mapleFU |
||||||
throw ParquetException("AesDecryptor was wiped out"); | ||||||
} | ||||||
} | ||||||
|
||||||
EVP_CIPHER_CTX* ctx_; | ||||||
int32_t aes_mode_; | ||||||
int32_t key_length_; | ||||||
|
@@ -714,6 +730,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) { | ||||||
CheckValid(); | ||||||
|
||||||
if (static_cast<size_t>(key_length_) != key.size()) { | ||||||
std::stringstream ss; | ||||||
ss << "Wrong key length " << key.size() << ". Should be " << key_length_; | ||||||
|
@@ -806,4 +824,7 @@ void RandBytes(unsigned char* buf, size_t num) { | |||||
|
||||||
void EnsureBackendInitialized() { openssl::EnsureInitialized(); } | ||||||
|
||||||
#undef ENCRYPT_INIT | ||||||
#undef DECRYPT_INIT | ||||||
|
||||||
} // namespace parquet::encryption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.