Skip to content

Commit dc63691

Browse files
fix: guard multiBufferBuilder UnsafeAppend against short copy (#896)
1 parent 8316f04 commit dc63691

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

arrow/array/bufferbuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ func (b *multiBufferBuilder) UnsafeAppend(hdr *arrow.ViewHeader, val []byte) {
243243
hdr.SetIndexOffset(int32(idx), int32(offset))
244244

245245
n := copy(buf.Buf()[offset:], val)
246+
if n != len(val) {
247+
panic("arrow/array: multibufferbuilder could not append full value")
248+
}
246249
buf.ResizeNoShrink(offset + n)
247250
}
248251

arrow/array/bufferbuilder_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package array
18+
19+
import (
20+
"testing"
21+
22+
"github.com/apache/arrow-go/v18/arrow"
23+
"github.com/apache/arrow-go/v18/arrow/memory"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestMultiBufferBuilderUnsafeAppendPanicsOnTruncatedCopy(t *testing.T) {
28+
builder := multiBufferBuilder{mem: memory.NewGoAllocator(), blockSize: 8}
29+
builder.Retain()
30+
defer builder.Release()
31+
32+
buf := memory.NewResizableBuffer(builder.mem)
33+
buf.ResizeNoShrink(1)
34+
builder.blocks = []*memory.Buffer{buf}
35+
builder.currentOutBuffer = 0
36+
37+
var hdr arrow.ViewHeader
38+
assert.Panics(t, func() {
39+
builder.UnsafeAppend(&hdr, make([]byte, 64))
40+
})
41+
}

0 commit comments

Comments
 (0)