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 f1ab6442 fix(arrow/array,arrow/scalar): reject `int32` offset and size 
overflow in list builders (#1648)
f1ab6442 is described below

commit f1ab6442059e31d1b59cb9daad35f3422b66093b
Author: Harrison Crosse <[email protected]>
AuthorDate: Fri Nov 20 17:07:27 2026 -0500

    fix(arrow/array,arrow/scalar): reject `int32` offset and size overflow in 
list builders (#1648)
    
    ### Rationale for this change
    
    `ListBuilder` and `ListViewBuilder` narrow child lengths, offsets and sizes 
to `int32` without checking bounds, so values above `math.MaxInt32` wrap to 
negative numbers and produce invalid arrays. In `arrow/scalar`, `AppendSlice` 
reserves and mutates list builders without checking whether the combined child 
length exceeds the builder offset limit.
    
    ### What changes are included in this PR?
    
    `ListBuilder` now checks offsets against `math.MaxInt32` before changing 
lengths or validity in `Append`, `AppendNull`, `AppendNulls` and 
`AppendEmptyValues`. `ListViewBuilder` now checks offsets, sizes and their sum 
against `math.MaxInt32` in `AppendWithSize`, `AppendDimensions`, `AppendNulls`, 
`AppendEmptyValues` and `UnmarshalOne`. Both builders panic before writing 
wrapped `int32` values.
    
    In `arrow/scalar`, `AppendSlice` checks existing child length and incoming 
list lengths against `math.MaxInt32` for `ListBuilder`, `ListViewBuilder` and 
`MapBuilder` and against `math.MaxInt` for large list builders, returning 
`arrow.ErrInvalid` before reserving child storage or appending values.
    
    ### Are these changes tested?
    
    Yes. I added unit tests covering `ListBuilder` and `ListViewBuilder` 
overflow panics, unmutated builder state after rejected bulk appends, and 
`arrow.ErrInvalid` returns from `scalar.AppendSlice` for list, list view and 
map builders.
    
    ### Are there any user-facing changes?
    
    Yes. List builders panic instead of writing wrapped `int32` offsets or 
sizes, and `scalar.AppendSlice` returns `arrow.ErrInvalid` on overflow. There 
is no API change.
---
 arrow/array/list.go                  |  70 +++++++++++---
 arrow/array/list_overflow_test.go    | 183 +++++++++++++++++++++++++++++++++++
 arrow/compute/scalar_nested_test.go  |   2 +-
 arrow/scalar/append.go               |  23 ++++-
 arrow/scalar/append_overflow_test.go |  93 ++++++++++++++++++
 5 files changed, 356 insertions(+), 15 deletions(-)

diff --git a/arrow/array/list.go b/arrow/array/list.go
index 463da03b..29398273 100644
--- a/arrow/array/list.go
+++ b/arrow/array/list.go
@@ -19,6 +19,7 @@ package array
 import (
        "bytes"
        "fmt"
+       "math"
        "strings"
 
        "github.com/apache/arrow-go/v18/arrow"
@@ -318,6 +319,25 @@ type LargeListBuilder struct {
        baseListBuilder
 }
 
+func checkListOffsetInt32(o int) int32 {
+       if o < 0 || o > math.MaxInt32 {
+               panic("arrow/array: list offset overflow")
+       }
+       return int32(o)
+}
+
+func checkListViewDimensionsInt32(offset, size int) {
+       if offset < 0 || offset > math.MaxInt32 {
+               panic("arrow/array: list-view offset overflow")
+       }
+       if size < 0 || size > math.MaxInt32 {
+               panic("arrow/array: list-view size overflow")
+       }
+       if int64(offset)+int64(size) > math.MaxInt32 {
+               panic("arrow/array: list-view offset and size overflow")
+       }
+}
+
 // NewListBuilder returns a builder, using the provided memory allocator.
 // The created list builder will create a list whose elements will be of type 
etype.
 func NewListBuilder(mem memory.Allocator, etype arrow.DataType) *ListBuilder {
@@ -328,7 +348,7 @@ func NewListBuilder(mem memory.Allocator, etype 
arrow.DataType) *ListBuilder {
                        values:          NewBuilder(mem, etype),
                        offsets:         offsetBldr,
                        dt:              arrow.ListOf(etype),
-                       appendOffsetVal: func(o int) { 
offsetBldr.Append(int32(o)) },
+                       appendOffsetVal: func(o int) { 
offsetBldr.Append(checkListOffsetInt32(o)) },
                },
        }
        lb.refCount.Add(1)
@@ -345,7 +365,7 @@ func NewListBuilderWithField(mem memory.Allocator, field 
arrow.Field) *ListBuild
                        values:          NewBuilder(mem, field.Type),
                        offsets:         offsetBldr,
                        dt:              arrow.ListOfField(field),
-                       appendOffsetVal: func(o int) { 
offsetBldr.Append(int32(o)) },
+                       appendOffsetVal: func(o int) { 
offsetBldr.Append(checkListOffsetInt32(o)) },
                },
        }
        lb.refCount.Add(1)
@@ -422,9 +442,10 @@ func (b *baseListBuilder) appendNextOffset() {
 func unsafeAppendRepeatedInt(builder Builder, value, n int) {
        switch builder := builder.(type) {
        case *Int32Builder:
+               val := checkListOffsetInt32(value)
                end := builder.length + n
                for i := builder.length; i < end; i++ {
-                       builder.rawData[i] = int32(value)
+                       builder.rawData[i] = val
                }
                builder.unsafeAppendBoolsToBitmap(nil, n)
        case *Int64Builder:
@@ -440,8 +461,8 @@ func unsafeAppendRepeatedInt(builder Builder, value, n int) 
{
 
 func (b *baseListBuilder) Append(v bool) {
        b.Reserve(1)
-       b.unsafeAppendBoolToBitmap(v)
        b.appendNextOffset()
+       b.unsafeAppendBoolToBitmap(v)
 }
 
 func (b *baseListBuilder) AppendWithSize(v bool, _ int) {
@@ -450,8 +471,8 @@ func (b *baseListBuilder) AppendWithSize(v bool, _ int) {
 
 func (b *baseListBuilder) AppendNull() {
        b.Reserve(1)
-       b.unsafeAppendBoolToBitmap(false)
        b.appendNextOffset()
+       b.unsafeAppendBoolToBitmap(false)
 }
 
 func (b *baseListBuilder) AppendNulls(n int) {
@@ -460,10 +481,10 @@ func (b *baseListBuilder) AppendNulls(n int) {
        }
 
        b.Reserve(n)
+       unsafeAppendRepeatedInt(b.offsets, b.values.Len(), n)
        bitutil.SetBitsTo(b.nullBitmap.Bytes(), int64(b.length), int64(n), 
false)
        b.length += n
        b.nulls += n
-       unsafeAppendRepeatedInt(b.offsets, b.values.Len(), n)
 }
 
 func (b *baseListBuilder) AppendEmptyValue() {
@@ -476,8 +497,8 @@ func (b *baseListBuilder) AppendEmptyValues(n int) {
        }
 
        b.Reserve(n)
-       b.unsafeAppendBoolsToBitmap(nil, n)
        unsafeAppendRepeatedInt(b.offsets, b.values.Len(), n)
+       b.unsafeAppendBoolsToBitmap(nil, n)
 }
 
 func (b *ListBuilder) AppendValues(offsets []int32, valid []bool) {
@@ -1102,6 +1123,7 @@ type baseListViewBuilder struct {
 
        // actual list-view type
        dt              arrow.DataType
+       checkDimensions func(offset, size int)
        appendOffsetVal func(int)
        appendSizeVal   func(int)
 }
@@ -1127,6 +1149,7 @@ func NewListViewBuilder(mem memory.Allocator, etype 
arrow.DataType) *ListViewBui
                        offsets:         offsetBldr,
                        sizes:           sizeBldr,
                        dt:              arrow.ListViewOf(etype),
+                       checkDimensions: checkListViewDimensionsInt32,
                        appendOffsetVal: func(o int) { 
offsetBldr.Append(int32(o)) },
                        appendSizeVal:   func(s int) { 
sizeBldr.Append(int32(s)) },
                },
@@ -1147,6 +1170,7 @@ func NewListViewBuilderWithField(mem memory.Allocator, 
field arrow.Field) *ListV
                        offsets:         offsetBldr,
                        sizes:           sizeBldr,
                        dt:              arrow.ListViewOfField(field),
+                       checkDimensions: checkListViewDimensionsInt32,
                        appendOffsetVal: func(o int) { 
offsetBldr.Append(int32(o)) },
                        appendSizeVal:   func(s int) { 
sizeBldr.Append(int32(s)) },
                },
@@ -1227,6 +1251,9 @@ func (b *baseListViewBuilder) Release() {
 }
 
 func (b *baseListViewBuilder) AppendDimensions(offset int, listSize int) {
+       if b.checkDimensions != nil {
+               b.checkDimensions(offset, listSize)
+       }
        b.Reserve(1)
        b.unsafeAppendBoolToBitmap(true)
        b.appendOffsetVal(offset)
@@ -1239,9 +1266,13 @@ func (b *baseListViewBuilder) Append(v bool) {
 
 func (b *baseListViewBuilder) AppendWithSize(v bool, listSize int) {
        debug.Assert(v || listSize == 0, "invalid list-view should have size 0")
+       offset := b.values.Len()
+       if b.checkDimensions != nil {
+               b.checkDimensions(offset, listSize)
+       }
        b.Reserve(1)
        b.unsafeAppendBoolToBitmap(v)
-       b.appendOffsetVal(b.values.Len())
+       b.appendOffsetVal(offset)
        b.appendSizeVal(listSize)
 }
 
@@ -1253,6 +1284,9 @@ func (b *baseListViewBuilder) AppendNulls(n int) {
        if n <= 0 {
                return
        }
+       if b.checkDimensions != nil {
+               b.checkDimensions(b.values.Len(), 0)
+       }
 
        b.Reserve(n)
        bitutil.SetBitsTo(b.nullBitmap.Bytes(), int64(b.length), int64(n), 
false)
@@ -1269,6 +1303,9 @@ func (b *baseListViewBuilder) AppendEmptyValues(n int) {
        if n <= 0 {
                return
        }
+       if b.checkDimensions != nil {
+               b.checkDimensions(b.values.Len(), 0)
+       }
 
        b.Reserve(n)
        b.unsafeAppendBoolsToBitmap(nil, n)
@@ -1435,15 +1472,24 @@ func (b *baseListViewBuilder) UnmarshalOne(dec 
*json.Decoder) error {
                        return err
                }
                // consume ']'
-               _, err := dec.Token()
+               if _, err := dec.Token(); err != nil {
+                       return err
+               }
+               // Unlike the sizes passed to AppendWithSize, a JSON list's 
size comes from
+               // the decoded data, so overflow is reported instead of 
panicking.
+               size := b.values.Len() - offset
+               if b.checkDimensions != nil && (size < 0 || size > 
math.MaxInt32 ||
+                       int64(offset)+int64(size) > math.MaxInt32) {
+                       return fmt.Errorf("%w: list-view size overflow", 
arrow.ErrInvalid)
+               }
                // replace the last size with the actual size
                switch b.sizes.(type) {
                case *Int32Builder:
-                       b.sizes.(*Int32Builder).rawData[b.sizes.Len()-1] = 
int32(b.values.Len() - offset)
+                       b.sizes.(*Int32Builder).rawData[b.sizes.Len()-1] = 
int32(size)
                case *Int64Builder:
-                       b.sizes.(*Int64Builder).rawData[b.sizes.Len()-1] = 
int64(b.values.Len() - offset)
+                       b.sizes.(*Int64Builder).rawData[b.sizes.Len()-1] = 
int64(size)
                }
-               return err
+               return nil
        case nil:
                b.AppendNull()
        default:
diff --git a/arrow/array/list_overflow_test.go 
b/arrow/array/list_overflow_test.go
new file mode 100644
index 00000000..8c87567f
--- /dev/null
+++ b/arrow/array/list_overflow_test.go
@@ -0,0 +1,183 @@
+// 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 array
+
+import (
+       "math"
+       "strconv"
+       "testing"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+var overInt32 int64 = math.MaxInt32 + 1
+
+func TestListViewBuilderRejectsInt32Overflow(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       bldr := NewListViewBuilder(mem, arrow.Null)
+       defer bldr.Release()
+
+       bldr.AppendWithSize(true, 1)
+       bldr.ValueBuilder().(*NullBuilder).AppendNull()
+
+       assert.PanicsWithValue(t, "arrow/array: list-view size overflow", 
func() {
+               bldr.AppendWithSize(true, -1)
+       })
+       assert.PanicsWithValue(t, "arrow/array: list-view offset and size 
overflow", func() {
+               bldr.AppendWithSize(true, math.MaxInt32)
+       })
+       assert.PanicsWithValue(t, "arrow/array: list-view offset overflow", 
func() {
+               bldr.AppendDimensions(-1, 0)
+       })
+       assert.PanicsWithValue(t, "arrow/array: list-view offset and size 
overflow", func() {
+               bldr.AppendDimensions(math.MaxInt32, 1)
+       })
+
+       t.Run("64bit", func(t *testing.T) {
+               if strconv.IntSize == 32 {
+                       t.Skip("requires 64-bit int")
+               }
+
+               assert.PanicsWithValue(t, "arrow/array: list-view size 
overflow", func() {
+                       bldr.AppendWithSize(true, int(overInt32))
+               })
+               assert.PanicsWithValue(t, "arrow/array: list-view offset 
overflow", func() {
+                       bldr.AppendDimensions(int(overInt32), 0)
+               })
+               assert.PanicsWithValue(t, "arrow/array: list-view size 
overflow", func() {
+                       bldr.AppendDimensions(0, int(overInt32))
+               })
+       })
+
+       assert.Equal(t, 1, bldr.Len())
+       arr := bldr.NewListViewArray()
+       defer arr.Release()
+       require.NoError(t, arr.ValidateFull())
+       assert.Equal(t, 1, arr.Len())
+}
+
+func TestListViewBuilderBulkOverflowLeavesBuilderUnmutated(t *testing.T) {
+       if strconv.IntSize == 32 {
+               t.Skip("requires 64-bit int")
+       }
+
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       bldr := NewListViewBuilder(mem, arrow.Null)
+       defer bldr.Release()
+
+       bldr.AppendWithSize(true, 1)
+       vb := bldr.ValueBuilder().(*NullBuilder)
+       vb.length = int(overInt32)
+       vb.nulls = int(overInt32)
+
+       assert.PanicsWithValue(t, "arrow/array: list-view offset overflow", 
func() {
+               bldr.AppendNulls(2)
+       })
+       assert.Equal(t, 1, bldr.Len())
+       assert.Equal(t, 0, bldr.NullN())
+       assert.Equal(t, 1, bldr.offsets.Len())
+       assert.Equal(t, 1, bldr.sizes.Len())
+
+       assert.PanicsWithValue(t, "arrow/array: list-view offset overflow", 
func() {
+               bldr.AppendEmptyValues(2)
+       })
+       assert.Equal(t, 1, bldr.Len())
+       assert.Equal(t, 0, bldr.NullN())
+       assert.Equal(t, 1, bldr.offsets.Len())
+       assert.Equal(t, 1, bldr.sizes.Len())
+
+       vb.length = 1
+       vb.nulls = 1
+       arr := bldr.NewListViewArray()
+       defer arr.Release()
+       require.NoError(t, arr.ValidateFull())
+       assert.Equal(t, 1, arr.Len())
+}
+
+func TestListBuilderRejectsInt32OffsetOverflow(t *testing.T) {
+       if strconv.IntSize == 32 {
+               t.Skip("requires 64-bit int")
+       }
+
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       bldr := NewListBuilder(mem, arrow.Null)
+       defer bldr.Release()
+
+       bldr.Append(true)
+       vb := bldr.ValueBuilder().(*NullBuilder)
+       vb.length = int(overInt32)
+       vb.nulls = int(overInt32)
+
+       assert.PanicsWithValue(t, "arrow/array: list offset overflow", func() {
+               bldr.Append(true)
+       })
+       assert.PanicsWithValue(t, "arrow/array: list offset overflow", func() {
+               bldr.AppendNull()
+       })
+       assert.PanicsWithValue(t, "arrow/array: list offset overflow", func() {
+               bldr.AppendNulls(2)
+       })
+       assert.PanicsWithValue(t, "arrow/array: list offset overflow", func() {
+               bldr.AppendEmptyValues(2)
+       })
+       assert.Equal(t, 1, bldr.Len())
+
+       // Reset child length to a valid value so the builder can be cleanly 
finalized.
+       vb.length = 1
+       vb.nulls = 1
+       arr := bldr.NewListArray()
+       defer arr.Release()
+       assert.Equal(t, 1, arr.Len())
+}
+
+func TestListViewBuilderUnmarshalOneRejectsInt32Overflow(t *testing.T) {
+       if strconv.IntSize == 32 {
+               t.Skip("requires 64-bit int")
+       }
+
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       bldr := NewListViewBuilder(mem, arrow.Null)
+       defer bldr.Release()
+
+       // A JSON list's size is only known after its elements are decoded, so 
seed the
+       // child length to make the decoded offset and size exceed the int32 
domain.
+       vb := bldr.ValueBuilder().(*NullBuilder)
+       vb.length = math.MaxInt32
+       vb.nulls = math.MaxInt32
+
+       err := bldr.AppendValueFromString("[null]")
+       require.ErrorIs(t, err, arrow.ErrInvalid)
+       assert.Contains(t, err.Error(), "list-view size overflow")
+
+       vb.length = 1
+       vb.nulls = 1
+       arr := bldr.NewListViewArray()
+       defer arr.Release()
+       require.NoError(t, arr.ValidateFull())
+       assert.Equal(t, 1, arr.Len())
+}
diff --git a/arrow/compute/scalar_nested_test.go 
b/arrow/compute/scalar_nested_test.go
index bd1b4ed8..b31b1b7f 100644
--- a/arrow/compute/scalar_nested_test.go
+++ b/arrow/compute/scalar_nested_test.go
@@ -379,7 +379,7 @@ func TestListElementRejectsInvalidListViewOffsets(t 
*testing.T) {
                {"list view negative offset", func(mem memory.Allocator) 
arrow.Array {
                        builder := array.NewListViewBuilder(mem, 
arrow.PrimitiveTypes.Int32)
                        builder.ValueBuilder().(*array.Int32Builder).Append(7)
-                       builder.AppendDimensions(-1, 1)
+                       builder.AppendValuesWithSizes([]int32{-1}, []int32{1}, 
[]bool{true})
                        result := builder.NewArray()
                        builder.Release()
                        return result
diff --git a/arrow/scalar/append.go b/arrow/scalar/append.go
index 88e1d989..c504d01b 100644
--- a/arrow/scalar/append.go
+++ b/arrow/scalar/append.go
@@ -20,6 +20,7 @@ package scalar
 
 import (
        "fmt"
+       "math"
 
        "github.com/apache/arrow-go/v18/arrow"
        "github.com/apache/arrow-go/v18/arrow/array"
@@ -181,12 +182,30 @@ func appendToBldr(bldr array.Builder, scalars []Scalar) 
error {
        case *array.BinaryViewBuilder:
                appendBinary(bldr, scalars)
        case array.ListLikeBuilder:
-               var numChildren int
+               limit := math.MaxInt
+               existingLen := bldr.ValueBuilder().Len()
+               switch b := bldr.(type) {
+               case *array.ListBuilder, *array.ListViewBuilder:
+                       limit = math.MaxInt32
+               case *array.MapBuilder:
+                       limit = math.MaxInt32
+                       existingLen = max(existingLen, b.KeyBuilder().Len(), 
b.ItemBuilder().Len())
+               }
+               if existingLen > limit {
+                       return fmt.Errorf("%w: list child length exceeds 
maximum %d", arrow.ErrInvalid, limit)
+               }
+               remaining := limit - existingLen
+               numChildren := 0
                for _, s := range scalars {
                        if !s.IsValid() {
                                continue
                        }
-                       numChildren += s.(ListScalar).GetList().Len()
+                       n := s.(ListScalar).GetList().Len()
+                       if n > remaining {
+                               return fmt.Errorf("%w: list child length 
exceeds maximum %d", arrow.ErrInvalid, limit)
+                       }
+                       remaining -= n
+                       numChildren += n
                }
                bldr.ValueBuilder().Reserve(numChildren)
 
diff --git a/arrow/scalar/append_overflow_test.go 
b/arrow/scalar/append_overflow_test.go
new file mode 100644
index 00000000..4ac83984
--- /dev/null
+++ b/arrow/scalar/append_overflow_test.go
@@ -0,0 +1,93 @@
+// 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 scalar_test
+
+import (
+       "math"
+       "testing"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/array"
+       "github.com/apache/arrow-go/v18/arrow/memory"
+       "github.com/apache/arrow-go/v18/arrow/scalar"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestAppendListOverflowReturnsInvalid(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       bigNull := array.NewNull(math.MaxInt32)
+       defer bigNull.Release()
+       oneNull := array.NewNull(1)
+       defer oneNull.Release()
+
+       t.Run("ListBuilder", func(t *testing.T) {
+               bldr := array.NewListBuilder(mem, arrow.Null)
+               defer bldr.Release()
+
+               sBig := scalar.NewListScalar(bigNull)
+               sOne := scalar.NewListScalar(oneNull)
+
+               err := scalar.AppendSlice(bldr, []scalar.Scalar{sBig, sOne})
+               require.ErrorIs(t, err, arrow.ErrInvalid)
+               assert.Equal(t, 0, bldr.Len())
+               assert.Equal(t, 0, bldr.ValueBuilder().Len())
+       })
+
+       t.Run("ListViewBuilder", func(t *testing.T) {
+               bldr := array.NewListViewBuilder(mem, arrow.Null)
+               defer bldr.Release()
+
+               sBig := scalar.NewListViewScalar(bigNull)
+               sOne := scalar.NewListViewScalar(oneNull)
+
+               err := scalar.AppendSlice(bldr, []scalar.Scalar{sBig, sOne})
+               require.ErrorIs(t, err, arrow.ErrInvalid)
+               assert.Equal(t, 0, bldr.Len())
+               assert.Equal(t, 0, bldr.ValueBuilder().Len())
+       })
+
+       t.Run("MapBuilder", func(t *testing.T) {
+               bldr := array.NewMapBuilder(mem, arrow.Null, arrow.Null, false)
+               defer bldr.Release()
+
+               structType := 
bldr.Type().(*arrow.MapType).Elem().(*arrow.StructType)
+               bigData := array.NewData(structType, math.MaxInt32, 
[]*memory.Buffer{nil}, []arrow.ArrayData{bigNull.Data(), bigNull.Data()}, 0, 0)
+               defer bigData.Release()
+               bigEntries := array.NewStructData(bigData)
+               defer bigEntries.Release()
+
+               oneData := array.NewData(structType, 1, []*memory.Buffer{nil}, 
[]arrow.ArrayData{oneNull.Data(), oneNull.Data()}, 0, 0)
+               defer oneData.Release()
+               oneEntries := array.NewStructData(oneData)
+               defer oneEntries.Release()
+
+               sBig := scalar.NewMapScalar(bigEntries)
+               defer sBig.Release()
+               sOne := scalar.NewMapScalar(oneEntries)
+               defer sOne.Release()
+
+               err := scalar.AppendSlice(bldr, []scalar.Scalar{sBig, sOne})
+               require.ErrorIs(t, err, arrow.ErrInvalid)
+               assert.Equal(t, 0, bldr.Len())
+               assert.Equal(t, 0, bldr.ValueBuilder().Len())
+               assert.Equal(t, 0, bldr.KeyBuilder().Len())
+               assert.Equal(t, 0, bldr.ItemBuilder().Len())
+       })
+}

Reply via email to