This is an automated email from the ASF dual-hosted git repository.

apitrou 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 0fbfffbf42 GH-38039: [C++][Parquet] Fix segfault getting compression 
level for a Parquet column (#38025)
0fbfffbf42 is described below

commit 0fbfffbf42a42577c4855cfdd232cf069e76ae87
Author: Adam Reeve <[email protected]>
AuthorDate: Fri Oct 6 01:44:17 2023 +1300

    GH-38039: [C++][Parquet] Fix segfault getting compression level for a 
Parquet column (#38025)
    
    ### Rationale for this change
    
    After the changes in #35886, getting the compression level for a Parquet 
column segfaults if the compression level or other options weren't previously 
set
    
    ### What changes are included in this PR?
    
    Adds a null check on the codec options of the column  properties before 
trying to access the compression level.
    
    ### Are these changes tested?
    
    Yes, I added a unit test.
    
    ### Are there any user-facing changes?
    
    This fixes a regression added after 13.0.0 so isn't a user-facing fix
    * Closes: #38039
    
    Authored-by: Adam Reeve <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/parquet/properties.h       | 7 ++++++-
 cpp/src/parquet/properties_test.cc | 9 +++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/cpp/src/parquet/properties.h b/cpp/src/parquet/properties.h
index bdc5b15332..9344181d3f 100644
--- a/cpp/src/parquet/properties.h
+++ b/cpp/src/parquet/properties.h
@@ -196,7 +196,12 @@ class PARQUET_EXPORT ColumnProperties {
 
   size_t max_statistics_size() const { return max_stats_size_; }
 
-  int compression_level() const { return codec_options_->compression_level; }
+  int compression_level() const {
+    if (!codec_options_) {
+      return ::arrow::util::kUseDefaultCompressionLevel;
+    }
+    return codec_options_->compression_level;
+  }
 
   const std::shared_ptr<CodecOptions>& codec_options() const { return 
codec_options_; }
 
diff --git a/cpp/src/parquet/properties_test.cc 
b/cpp/src/parquet/properties_test.cc
index 96c3a63b83..b2c574413a 100644
--- a/cpp/src/parquet/properties_test.cc
+++ b/cpp/src/parquet/properties_test.cc
@@ -49,6 +49,15 @@ TEST(TestWriterProperties, Basics) {
   ASSERT_FALSE(props->page_checksum_enabled());
 }
 
+TEST(TestWriterProperties, DefaultCompression) {
+  std::shared_ptr<WriterProperties> props = 
WriterProperties::Builder().build();
+
+  ASSERT_EQ(props->compression(ColumnPath::FromDotString("any")),
+            Compression::UNCOMPRESSED);
+  ASSERT_EQ(props->compression_level(ColumnPath::FromDotString("any")),
+            ::arrow::util::kUseDefaultCompressionLevel);
+}
+
 TEST(TestWriterProperties, AdvancedHandling) {
   WriterProperties::Builder builder;
   builder.compression("gzip", Compression::GZIP);

Reply via email to