adamreeve commented on code in PR #43195:
URL: https://github.com/apache/arrow/pull/43195#discussion_r1671581239


##########
cpp/src/parquet/encryption/encryption_internal.cc:
##########
@@ -137,30 +156,45 @@ 
AesEncryptor::AesEncryptorImpl::AesEncryptorImpl(ParquetCipher::type alg_id, int
   }
 }
 
-int AesEncryptor::AesEncryptorImpl::SignedFooterEncrypt(
-    const uint8_t* footer, int footer_len, const uint8_t* key, int key_len,
-    const uint8_t* aad, int aad_len, const uint8_t* nonce, uint8_t* 
encrypted_footer) {
-  if (key_length_ != key_len) {
+int 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) {
+  if (static_cast<size_t>(key_length_) != key.size()) {
+    std::stringstream ss;
+    ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
+    throw ParquetException(ss.str());
+  }
+
+  if (encrypted_footer.size() < footer.size() + ciphertext_size_delta_) {
     std::stringstream ss;
-    ss << "Wrong key length " << key_len << ". Should be " << key_length_;
+    ss << "Encrypted footer buffer length " << encrypted_footer.size()
+       << " is insufficient for footer length " << footer.size();
     throw ParquetException(ss.str());
   }
 
   if (kGcmMode != aes_mode_) {
     throw ParquetException("Must use AES GCM (metadata) encryptor");
   }
 
-  return GcmEncrypt(footer, footer_len, key, key_len, nonce, aad, aad_len,
-                    encrypted_footer);
+  return GcmEncrypt(footer, key, nonce, aad, encrypted_footer);
 }
 
-int AesEncryptor::AesEncryptorImpl::Encrypt(const uint8_t* plaintext, int 
plaintext_len,
-                                            const uint8_t* key, int key_len,
-                                            const uint8_t* aad, int aad_len,
-                                            uint8_t* ciphertext) {
-  if (key_length_ != key_len) {
+int AesEncryptor::AesEncryptorImpl::Encrypt(span<const uint8_t> plaintext,
+                                            span<const uint8_t> key,
+                                            span<const uint8_t> aad,
+                                            span<uint8_t> ciphertext) {
+  if (static_cast<size_t>(key_length_) != key.size()) {
+    std::stringstream ss;
+    ss << "Wrong key length " << key.size() << ". Should be " << key_length_;
+    throw ParquetException(ss.str());
+  }
+
+  if (ciphertext.size() < plaintext.size() + ciphertext_size_delta_) {

Review Comment:
   The extra tag in `GCM` mode is accounted for in `ciphertext_size_delta_` 
already at 
https://github.com/apache/arrow/blob/031497ddab5ce497c49b87d7125bf5c01bf80f48/cpp/src/parquet/encryption/encryption_internal.cc#L101,
 so I think it's fine to check this once here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to