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 91fb6bf1 fix(parquet/internal/encoding): don't panic decoding zero 
BYTE_STREAM_SPLIT values without SIMD (#1579)
91fb6bf1 is described below

commit 91fb6bf1bf4cace5858d7a5de0751183a9f91575
Author: Matt Topol <[email protected]>
AuthorDate: Tue Nov 17 10:55:40 2026 -0500

    fix(parquet/internal/encoding): don't panic decoding zero BYTE_STREAM_SPLIT 
values without SIMD (#1579)
    
    ### Rationale for this change
    
    `ByteStreamSplitDecoder.Decode` for 4- and 8-byte types panics with
    `index out of range [0] with length 0` when there is nothing left to
    decode, but only when the pure Go implementation is used (`-tags noasm`,
    or a CPU without AVX2/NEON). The pure Go functions take `&out[0]` of an
    empty slice. The AVX2 and NEON wrappers already return early for zero
    values, so the default build on amd64 and arm64 returns `0, nil`.
    
    A column reader hits this when a page holds fewer values than its header
    claims and it asks the decoder for the rest.
    
    ### What changes are included in this PR?
    
    The pure Go width-4 and width-8 decode functions (little- and
    big-endian) return early for zero values, like the SIMD wrappers.
    
    ### Are these changes tested?
    
    Yes, `TestByteStreamSplitDecodeExhausted` decodes past the end of a page
    for int32 and int64. It panics without the fix under `-tags noasm`.
    
    ### Are there any user-facing changes?
    
    No API changes. Decoding an exhausted BYTE_STREAM_SPLIT page no longer
    panics in builds without SIMD.
---
 .../encoding/byte_stream_split_big_endian.go       |  6 ++++
 .../encoding/byte_stream_split_decode_test.go      | 34 ++++++++++++++++++++++
 .../encoding/byte_stream_split_little_endian.go    |  6 ++++
 3 files changed, 46 insertions(+)

diff --git a/parquet/internal/encoding/byte_stream_split_big_endian.go 
b/parquet/internal/encoding/byte_stream_split_big_endian.go
index 3b48c933..176fcf86 100644
--- a/parquet/internal/encoding/byte_stream_split_big_endian.go
+++ b/parquet/internal/encoding/byte_stream_split_big_endian.go
@@ -30,6 +30,9 @@ import (
 // byte order and are be decoded into the 'out' array in machine's native 
endianness.
 // 'out' must have space for at least len(data) bytes.
 func decodeByteStreamSplitBatchWidth4InByteOrderDefault(data []byte, nValues, 
stride int, out []byte) {
+       if nValues == 0 {
+               return
+       }
        const width = 4
        debug.Assert(len(out) >= nValues*width, "not enough space in output 
buffer for decoding")
        // the beginning of the data slice can be truncated, but for valid 
encoding we need at least (width-1)*stride+nValues bytes
@@ -51,6 +54,9 @@ func decodeByteStreamSplitBatchWidth4InByteOrderDefault(data 
[]byte, nValues, st
 // byte order and are be decoded into the 'out' array in machine's native 
endianness.
 // 'out' must have space for at least len(data) bytes.
 func decodeByteStreamSplitBatchWidth8InByteOrderDefault(data []byte, nValues, 
stride int, out []byte) {
+       if nValues == 0 {
+               return
+       }
        const width = 8
        debug.Assert(len(out) >= nValues*width, "not enough space in output 
buffer for decoding")
        debug.Assert(len(data) >= 7*stride+nValues, "not enough data for 
decoding")
diff --git a/parquet/internal/encoding/byte_stream_split_decode_test.go 
b/parquet/internal/encoding/byte_stream_split_decode_test.go
index f1d8cfb2..11c83b3a 100644
--- a/parquet/internal/encoding/byte_stream_split_decode_test.go
+++ b/parquet/internal/encoding/byte_stream_split_decode_test.go
@@ -73,6 +73,40 @@ func TestDecodeByteStreamSplitWidth4(t *testing.T) {
        }
 }
 
+// Decoding past the last value of a page reads nothing rather than panicking,
+// with or without the SIMD implementations.
+func TestByteStreamSplitDecodeExhausted(t *testing.T) {
+       t.Run("int32", func(t *testing.T) {
+               col := schema.NewColumn(schema.NewInt32Node("v", 
parquet.Repetitions.Required, -1), 0, 0)
+               dec := NewDecoder(parquet.Types.Int32, 
parquet.Encodings.ByteStreamSplit, col, memory.DefaultAllocator).(Int32Decoder)
+               require.NoError(t, dec.SetData(2, []byte{1, 2, 0, 0, 0, 0, 0, 
0}))
+
+               out := make([]int32, 4)
+               n, err := dec.Decode(out)
+               require.NoError(t, err)
+               require.Equal(t, []int32{1, 2}, out[:n])
+
+               n, err = dec.Decode(out)
+               require.NoError(t, err)
+               require.Zero(t, n)
+       })
+
+       t.Run("int64", func(t *testing.T) {
+               col := schema.NewColumn(schema.NewInt64Node("v", 
parquet.Repetitions.Required, -1), 0, 0)
+               dec := NewDecoder(parquet.Types.Int64, 
parquet.Encodings.ByteStreamSplit, col, memory.DefaultAllocator).(Int64Decoder)
+               require.NoError(t, dec.SetData(2, []byte{1, 2, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0}))
+
+               out := make([]int64, 4)
+               n, err := dec.Decode(out)
+               require.NoError(t, err)
+               require.Equal(t, []int64{1, 2}, out[:n])
+
+               n, err = dec.Decode(out)
+               require.NoError(t, err)
+               require.Zero(t, n)
+       })
+}
+
 func BenchmarkDecodeByteStreamSplitBatchWidth4(b *testing.B) {
        const width = 4
        sizes := []int{8, 10, 64, 100, 512, 1000, 4096, 10000, 32768, 100000, 
2097152, 10000000, 16777216}
diff --git a/parquet/internal/encoding/byte_stream_split_little_endian.go 
b/parquet/internal/encoding/byte_stream_split_little_endian.go
index fb812639..5175a77d 100644
--- a/parquet/internal/encoding/byte_stream_split_little_endian.go
+++ b/parquet/internal/encoding/byte_stream_split_little_endian.go
@@ -30,6 +30,9 @@ import (
 // byte order and are be decoded into the 'out' array in machine's native 
endianness.
 // 'out' must have space for at least len(data) bytes.
 func decodeByteStreamSplitBatchWidth4InByteOrderDefault(data []byte, nValues, 
stride int, out []byte) {
+       if nValues == 0 {
+               return
+       }
        const width = 4
        debug.Assert(len(out) >= nValues*width, "not enough space in output 
buffer for decoding")
        // the beginning of the data slice can be truncated, but for valid 
encoding we need at least (width-1)*stride+nValues bytes
@@ -50,6 +53,9 @@ func decodeByteStreamSplitBatchWidth4InByteOrderDefault(data 
[]byte, nValues, st
 // byte order and are be decoded into the 'out' array in machine's native 
endianness.
 // 'out' must have space for at least len(data) bytes.
 func decodeByteStreamSplitBatchWidth8InByteOrderDefault(data []byte, nValues, 
stride int, out []byte) {
+       if nValues == 0 {
+               return
+       }
        const width = 8
        debug.Assert(len(out) >= nValues*width, "not enough space in output 
buffer for decoding")
        debug.Assert(len(data) >= 7*stride+nValues, "not enough data for 
decoding")

Reply via email to