Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-5117

[Go] Panic when appending zero slices after initializing a builder

    XMLWordPrintableJSON

Details

    Description

      array.NewInt8Builder(memory.DefaultAllocator).AppendValues([]int8{}, []bool{})

      results in a panic

      === RUN TestArrowPanic
      --- FAIL: TestArrowPanic (0.00s)
      panic: runtime error: invalid memory address or nil pointer dereference [recovered]
       panic: runtime error: invalid memory address or nil pointer dereference
      [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x414f6fd]goroutine 5 [running]:
      testing.tRunner.func1(0xc000492a00)
       /usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:792 +0x387
      panic(0x4cd1fe0, 0x5bb3fb0)
       /usr/local/Cellar/go/1.11.5/libexec/src/runtime/panic.go:513 +0x1b9
      github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/memory.(*Buffer).Bytes(...)
       /Users/asubiotto/go/src/github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/memory/buffer.go:67
      github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array.(*builder).unsafeSetValid(0xc000382a80, 0x0)
       /Users/asubiotto/go/src/github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array/builder.go:184 +0x6d
      github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array.(*builder).unsafeAppendBoolsToBitmap(0xc000382a80, 0xc00040df88, 0x0, 0x0, 0x0)
       /Users/asubiotto/go/src/github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array/builder.go:146 +0x17a
      github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array.(*Int8Builder).AppendValues(0xc000382a80, 0xc00040df88, 0x0, 0x0, 0xc00040df88, 0x0, 0x0)
       /Users/asubiotto/go/src/github.com/cockroachdb/cockroach/vendor/github.com/apache/arrow/go/arrow/array/numericbuilder.gen.go:1168 +0xcb
      github.com/cockroachdb/cockroach/pkg/util/arrow_test.TestArrowPanic(0xc000492a00)
       /Users/asubiotto/go/src/github.com/cockroachdb/cockroach/pkg/util/arrow/record_batch_test.go:273 +0x9a
      testing.tRunner(0xc000492a00, 0x4ec5370)
       /usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:827 +0xbf
      created by testing.(*T).Run
       /usr/local/Cellar/go/1.11.5/libexec/src/testing/testing.go:878 +0x35cProcess finished with exit code 1

      due to the underlying null bitmap never being initialized. I believe the expectation is for `Resize` to initialize this bitmap. This never happens because a length of 0 (elements in this block) fails this check:

      func (b *builder) reserve(elements int, resize func(int)) {
          if b.length+elements > b.capacity {
              newCap := bitutil.NextPowerOf2(b.length + elements)
              resize(newCap)
          }
      }

      As far as I can tell the arguments to AppendValues are valid. I'd be happy to submit a patch but I can see several ways of fixing this so would prefer someone familiar with the code to take a look and define expectations in this case.

      Attachments

        Issue Links

          Activity

            People

              sbinet Sebastien Binet
              asubiotto Alfonso Subiotto
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 50m
                  2h 50m