hcrosse opened a new issue, #1525:
URL: https://github.com/apache/arrow-go/issues/1525

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Appending a null scalar with `scalar.Append` or `scalar.AppendSlice` can 
make `NewArray` panic. For fixed size binary, a value after the null can 
instead read back as zero bytes in an invalid array.
   
   I reproduced these failures on v18.8.0 and main, with Go 1.26.10 on macOS 
arm64.
   
   **Null struct**
   
   ```go
   dt := arrow.StructOf(arrow.Field{Name: "s", Type: arrow.BinaryTypes.String, 
Nullable: true})
   bldr := array.NewBuilder(memory.DefaultAllocator, dt)
   scalar.Append(bldr, scalar.MakeNullScalar(dt))
   arr := bldr.NewArray()
   ```
   
   Actual output starts with:
   
   ```text
   panic: arrow/array: string offset buffer must have at least 2 values
   ```
   
   Expected: `NewArray` returns a valid array containing one null struct, 
printed as `{[(null)]}`.
   
   **Fixed size binary**
   
   ```go
   dt := &arrow.FixedSizeBinaryType{ByteWidth: 4}
   src, _, _ := array.FromJSON(memory.DefaultAllocator, dt, 
strings.NewReader(`["YWJjZA==", null, "ZWZnaA=="]`))
   scalars := make([]scalar.Scalar, src.Len())
   for i := range scalars {
        scalars[i], _ = scalar.GetScalar(src, i)
   }
   bldr := array.NewBuilder(memory.DefaultAllocator, dt)
   scalar.AppendSlice(bldr, scalars)
   arr := bldr.NewArray()
   array.ValidateFull(arr)
   ```
   
   Actual validation error and result:
   
   ```text
   ValidateFull: arrow/array: buffer 1 is too small for offset 0 and length 3
   result: ["abcd" (null) "\x00\x00\x00\x00"]
   ```
   
   Expected: validation succeeds and the result remains `["abcd" (null) 
"efgh"]`.
   
   This also affects null fixed size lists and struct fields or union children 
that need offsets or child slots. Run end encoded children panic during the 
append itself. `exprs.ExecuteScalarExpression` reaches the same path for 
Substrait list literals containing null structs or intervals.
   
   **Cause**
   
   These null paths use `Append(false)` or `UnsafeAppendBoolToBitmap(false)`, 
which update validity without advancing value bytes, offsets or child slots. 
The builders' `AppendNull` methods perform that work.
   
   
https://github.com/apache/arrow-go/blob/be922ec557c08b06d9f8243023b08e192eaeaa1d/arrow/scalar/append.go#L128-L136
   
   
https://github.com/apache/arrow-go/blob/be922ec557c08b06d9f8243023b08e192eaeaa1d/arrow/scalar/append.go#L193-L220
   
   
https://github.com/apache/arrow-go/blob/be922ec557c08b06d9f8243023b08e192eaeaa1d/arrow/scalar/append.go#L233-L270
   
   I have a patch with tests and can open a PR.
   
   ### Component(s)
   
   Other
   


-- 
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]

Reply via email to