Copilot commented on code in PR #1602:
URL: https://github.com/apache/arrow-go/pull/1602#discussion_r4607834570
##########
arrow/scalar/append.go:
##########
@@ -190,13 +190,22 @@ func appendToBldr(bldr array.Builder, scalars []Scalar)
error {
}
bldr.ValueBuilder().Reserve(numChildren)
+ // List-view builders do not support Append and need the size
up front.
+ appendList := func(int) { bldr.Append(true) }
+ switch b := bldr.(type) {
+ case *array.ListViewBuilder:
+ appendList = func(n int) { b.AppendWithSize(true, n) }
+ case *array.LargeListViewBuilder:
+ appendList = func(n int) { b.AppendWithSize(true, n) }
+ }
+
for _, s := range scalars {
if !s.IsValid() {
bldr.AppendNull()
continue
}
- bldr.Append(true)
list := s.(ListScalar).GetList()
+ appendList(list.Len())
Review Comment:
Appending either list-view scalar with binary or nested-list children leaks
references because this loop never releases the scalars returned by
`GetScalar`. Release each `Releasable` child immediately after `Append`, before
returning any append error, so the input buffers can be freed when their owners
are released.
##########
arrow/scalar/append.go:
##########
@@ -190,13 +190,22 @@ func appendToBldr(bldr array.Builder, scalars []Scalar)
error {
}
bldr.ValueBuilder().Reserve(numChildren)
+ // List-view builders do not support Append and need the size
up front.
+ appendList := func(int) { bldr.Append(true) }
+ switch b := bldr.(type) {
+ case *array.ListViewBuilder:
+ appendList = func(n int) { b.AppendWithSize(true, n) }
Review Comment:
`AppendWithSize` narrows the scalar size and current child-builder length to
`int32` without checks. A size above `MaxInt32`, or a nonempty append whose
starting offset exceeds that limit after earlier appends, produces negative
dimensions and an invalid array. Preflight each size and cumulative starting
offset before reserving child capacity, returning `arrow.ErrInvalid` on
overflow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]