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

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 52432460 fix(parquet/metadata): return schema initialization errors 
(#1056)
52432460 is described below

commit 52432460eac86ccc5ed5cd87b31691a661f37485
Author: Minh Vu <[email protected]>
AuthorDate: Wed Aug 5 19:35:42 2026 +0200

    fix(parquet/metadata): return schema initialization errors (#1056)
    
    ### Rationale for this change
    
    `NewFileMetaData` discarded the error from `initSchema` and immediately
    initialized column orders. When malformed metadata could not produce a
    schema, this could dereference the unset schema and panic.
    
    ### What changes are included in this PR?
    
    Return the schema initialization error before touching column orders.
    
    ### Are these changes tested?
    
    Yes. A regression test serializes invalid schema metadata and verifies
    an error with no result.
    
    `go test ./parquet/metadata -run TestNewFileMetaDataReturnsSchemaErrors`
    
    ### Are there any user-facing changes?
    
    Malformed metadata now returns its schema error instead of potentially
    panicking.
---
 parquet/metadata/file.go               |  4 +++-
 parquet/metadata/file_internal_test.go | 38 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/parquet/metadata/file.go b/parquet/metadata/file.go
index 95a00571..2d4cf1b4 100644
--- a/parquet/metadata/file.go
+++ b/parquet/metadata/file.go
@@ -320,7 +320,9 @@ func NewFileMetaData(data []byte, fileDecryptor 
encryption.FileDecryptor) (*File
                FileDecryptor: fileDecryptor,
        }
 
-       f.initSchema()
+       if err := f.initSchema(); err != nil {
+               return nil, err
+       }
        f.initColumnOrders()
 
        return f, nil
diff --git a/parquet/metadata/file_internal_test.go 
b/parquet/metadata/file_internal_test.go
new file mode 100644
index 00000000..1b4c2790
--- /dev/null
+++ b/parquet/metadata/file_internal_test.go
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package metadata
+
+import (
+       "bytes"
+       "testing"
+
+       format "github.com/apache/arrow-go/v18/parquet/internal/gen-go/parquet"
+       "github.com/apache/arrow-go/v18/parquet/internal/thrift"
+       "github.com/stretchr/testify/require"
+)
+
+func TestNewFileMetaDataReturnsSchemaErrors(t *testing.T) {
+       fileMeta := format.NewFileMetaData()
+       var buf bytes.Buffer
+       _, err := thrift.NewThriftSerializer().Serialize(fileMeta, &buf, nil)
+       require.NoError(t, err)
+
+       meta, err := NewFileMetaData(buf.Bytes(), nil)
+       require.Error(t, err)
+       require.Nil(t, meta)
+}

Reply via email to