Skip to content

Commit 3cf9dc6

Browse files
committed
parquet: tighten encrypted bloom filter checks
1 parent 29f446e commit 3cf9dc6

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

cpp/src/parquet/bloom_filter.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace {
3737

3838
constexpr int32_t kCiphertextLengthSize = 4;
3939

40-
// Parse the little-endian length prefix and return the total ciphertext size
41-
// including the 4-byte length field itself.
40+
/// Parse the 4-byte little-endian length prefix and return the total ciphertext size,
41+
/// including the 4-byte length field itself.
4242
int64_t ParseCiphertextTotalLength(const uint8_t* data, int64_t length) {
4343
if (length < kCiphertextLengthSize) {
4444
throw ParquetException("Ciphertext length buffer is too small");
@@ -130,7 +130,8 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
130130
Decryptor* bitset_decryptor) {
131131
if (header_decryptor != nullptr || bitset_decryptor != nullptr) {
132132
if (header_decryptor == nullptr || bitset_decryptor == nullptr) {
133-
throw ParquetException("Bloom filter decryptors must be both provided");
133+
throw ParquetException(
134+
"Bloom filter decryptors must be both provided or both null");
134135
}
135136

136137
// Encrypted path: header and bitset are encrypted separately.

cpp/src/parquet/bloom_filter_reader.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ std::unique_ptr<BloomFilter> RowGroupBloomFilterReaderImpl::GetColumnBloomFilter
9090
std::unique_ptr<Decryptor> bitset_decryptor =
9191
InternalFileDecryptor::GetColumnDataDecryptorFactory(file_decryptor_.get(),
9292
crypto_metadata.get())();
93+
if (header_decryptor != nullptr || bitset_decryptor != nullptr) {
94+
constexpr auto kEncryptedOrdinalLimit = 32767;
95+
if (ARROW_PREDICT_FALSE(row_group_ordinal_ > kEncryptedOrdinalLimit)) {
96+
throw ParquetException("Encrypted files cannot contain more than 32767 row groups");
97+
}
98+
if (ARROW_PREDICT_FALSE(i > kEncryptedOrdinalLimit)) {
99+
throw ParquetException("Encrypted files cannot contain more than 32767 columns");
100+
}
101+
}
102+
93103
if (header_decryptor != nullptr) {
94104
UpdateDecryptor(header_decryptor.get(), row_group_ordinal_, static_cast<int16_t>(i),
95105
encryption::kBloomFilterHeader);
@@ -98,6 +108,7 @@ std::unique_ptr<BloomFilter> RowGroupBloomFilterReaderImpl::GetColumnBloomFilter
98108
UpdateDecryptor(bitset_decryptor.get(), row_group_ordinal_, static_cast<int16_t>(i),
99109
encryption::kBloomFilterBitset);
100110
}
111+
101112
const int64_t stream_length =
102113
bloom_filter_length ? *bloom_filter_length : file_size - *bloom_filter_offset;
103114
auto stream = ::arrow::io::RandomAccessFile::GetStream(input_, *bloom_filter_offset,

0 commit comments

Comments
 (0)