This is an automated email from the ASF dual-hosted git repository.
pitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 7ee15283bc9 GH-53518: [Parquet] Reject unsupported compression codecs
(#53522)
7ee15283bc9 is described below
commit 7ee15283bc9fac8b4e523b0b4640439b547ef0ff
Author: Divjot Arora <[email protected]>
AuthorDate: Tue Oct 13 14:42:53 2026 +0200
GH-53518: [Parquet] Reject unsupported compression codecs (#53522)
### Rationale for this change
See https://github.com/apache/arrow/issues/53518 for rationale. Treating
unknown compression codecs as `UNCOMPRESSED` is wrong and at best causes the
read to fail late during decoding and at worst yields incorrect results if the
compressed stream is actually a valid decodable set of bytes (very unlikely).
### What changes are included in this PR?
This PR causes unsupported compression codecs to fail a read eagerly during
Thrift parsing.
### Are these changes tested?
Yes, new test case added to `metadata_test.cc`
### Are there any user-facing changes?
No
### Was AI used for this PR?
**PR code and description written by:**
- [x] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [ ] AI
- [ ] Not reviewed
Closes #53518
* GitHub Issue: #53518
Authored-by: Divjot Arora <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
cpp/src/parquet/metadata_test.cc | 21 +++++++++++++++++++++
cpp/src/parquet/thrift_internal.h | 2 +-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/cpp/src/parquet/metadata_test.cc b/cpp/src/parquet/metadata_test.cc
index e6ff1f929d4..ee2f0619ebf 100644
--- a/cpp/src/parquet/metadata_test.cc
+++ b/cpp/src/parquet/metadata_test.cc
@@ -17,9 +17,13 @@
#include "parquet/metadata.h"
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <cstring>
+
#include "arrow/util/key_value_metadata.h"
+#include "parquet/exception.h"
#include "parquet/file_reader.h"
#include "parquet/file_writer.h"
#include "parquet/schema.h"
@@ -344,6 +348,23 @@ void AssertColumnChunkMinMax(const FileMetaData& metadata,
} // namespace
+TEST(Metadata, UnknownCompressionCodecThrows) {
+ format::FileMetaData thrift_metadata = SingleInt32MetadataWithStats();
+ auto metadata = ParseMetadata(SerializeMetadata(thrift_metadata));
+
+ auto& column_chunk = thrift_metadata.row_groups.at(0).columns.at(0);
+ const int32_t raw_codec = 8;
+ static_assert(sizeof(column_chunk.meta_data.codec) == sizeof(raw_codec));
+ std::memcpy(&column_chunk.meta_data.codec, &raw_codec, sizeof(raw_codec));
+
+ auto column = ColumnChunkMetaData::Make(&column_chunk,
metadata->schema()->Column(0));
+
+ EXPECT_THROW_THAT([&]() { column->compression(); }, ParquetException,
+ ::testing::Property(
+ &ParquetException::what,
+ ::testing::HasSubstr("Unsupported compression codec
value: 8")));
+}
+
TEST(Metadata, UnknownColumnOrderIgnoresMinMax) {
format::FileMetaData thrift_metadata = SingleInt32MetadataWithStats();
// Simulate an unsupported ColumnOrder value: unknown union fields are
skipped by
diff --git a/cpp/src/parquet/thrift_internal.h
b/cpp/src/parquet/thrift_internal.h
index a74d97c1e28..5a0fc7d70e6 100644
--- a/cpp/src/parquet/thrift_internal.h
+++ b/cpp/src/parquet/thrift_internal.h
@@ -227,7 +227,7 @@ inline typename Compression::type LoadEnumSafe(const
format::CompressionCodec::t
const auto max_value =
static_cast<decltype(raw_value)>(format::CompressionCodec::LZ4_RAW);
if (raw_value < min_value || raw_value > max_value) {
- return Compression::UNCOMPRESSED;
+ throw ParquetException("Unsupported compression codec value: ", raw_value);
}
return FromThriftUnsafe(*in);
}