adamreeve commented on code in PR #43413:
URL: https://github.com/apache/arrow/pull/43413#discussion_r1692255996
##########
cpp/src/parquet/encryption/encryption_internal.cc:
##########
@@ -758,9 +795,14 @@ void QuickUpdatePageAad(int32_t new_page_ordinal,
std::string* AAD) {
std::memcpy(AAD->data() + AAD->length() - 2, page_ordinal_bytes.data(), 2);
}
-void RandBytes(unsigned char* buf, int num) {
+void RandBytes(unsigned char* buf, size_t num) {
+ if (num > static_cast<size_t>(std::numeric_limits<int>::max())) {
+ std::stringstream ss;
+ ss << "Length " << num << " for RandBytes overflows int";
+ throw ParquetException(ss.str());
+ }
openssl::EnsureInitialized();
- RAND_bytes(buf, num);
+ RAND_bytes(buf, static_cast<int>(num));
Review Comment:
This seems to work fine from testing it.
Looking at the [RAND_bytes
documentation](https://docs.openssl.org/3.3/man3/RAND_bytes/) though, I notice
that it says that the return value should be checked as it's not always
guaranteed that random bytes can be generated.
I think this should probably be fixed but maybe in a separate PR?
--
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]