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 572fafb3 fix(array/record): bldr stop ignore unexpected EOF (#1341)
572fafb3 is described below

commit 572fafb3ed8fc9c936a3dfb048a110146c3faceb
Author: Willem Jan <[email protected]>
AuthorDate: Tue Oct 6 01:06:41 2026 +0200

    fix(array/record): bldr stop ignore unexpected EOF (#1341)
    
    ### Rationale for this change
    array/json_reader unmarshals records, but treats EOF as an end of the
    stream and swallows it. This leads to ignoring unexpected errors where
    the JSON was not valid: `{"a": 2`
    
    ### What changes are included in this PR?
    If a new record has started being processed, EOF is converted to
    UnexpectedEOF, so it will not be swallowed.
    
    ### Are these changes tested?
    Added a testcase.
    
    ### Are there any user-facing changes?
    No
    
    Co-authored-by: Willem Jan Noort <[email protected]>
---
 arrow/array/record.go    |  7 +++++++
 arrow/array/util_test.go | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/arrow/array/record.go b/arrow/array/record.go
index 704759b1..0a2b7fd6 100644
--- a/arrow/array/record.go
+++ b/arrow/array/record.go
@@ -18,7 +18,9 @@ package array
 
 import (
        "bytes"
+       "errors"
        "fmt"
+       "io"
        "iter"
        "strings"
        "sync/atomic"
@@ -607,6 +609,11 @@ func (b *RecordBuilder) unmarshalOne(dec *json.Decoder) 
(err error) {
        if delim, ok := t.(json.Delim); !ok || delim != '{' {
                return fmt.Errorf("record should start with '{', not %s", t)
        }
+       defer func() {
+               if errors.Is(err, io.EOF) {
+                       err = io.ErrUnexpectedEOF
+               }
+       }()
 
        keylist := make(map[string]bool)
        for dec.More() {
diff --git a/arrow/array/util_test.go b/arrow/array/util_test.go
index e8e496c8..652a3556 100644
--- a/arrow/array/util_test.go
+++ b/arrow/array/util_test.go
@@ -918,6 +918,23 @@ func 
TestRecordBuilderUnmarshalOnePreservesUserDecoderOptions(t *testing.T) {
        assert.EqualValues(t, int64(9223372036854775807), col.Value(0))
 }
 
+func TestRecordBuilderUnmarshalOneReturnUnexpectedEOF(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+       defer mem.AssertSize(t, 0)
+
+       schema := arrow.NewSchema([]arrow.Field{
+               {Name: "a", Type: arrow.PrimitiveTypes.Int64},
+       }, nil)
+
+       bldr := array.NewRecordBuilder(mem, schema)
+       defer bldr.Release()
+
+       src := strings.NewReader(`{"a": 9`)
+       dec := json.NewDecoder(src)
+
+       assert.ErrorIs(t, bldr.UnmarshalOne(dec), io.ErrUnexpectedEOF)
+}
+
 func TestDurationBuilderJSONStringInteger(t *testing.T) {
        mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
        defer mem.AssertSize(t, 0)

Reply via email to