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 7e088cdf fix(parquet/compress): read to the end of a Brotli stream
that fills dst (#1530)
7e088cdf is described below
commit 7e088cdf58c2bb6388deed332295c1b83ab99f98
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 11 18:20:34 2026 -0500
fix(parquet/compress): read to the end of a Brotli stream that fills dst
(#1530)
### Rationale for this change
arrow-go cannot read back some Brotli files it wrote. Empty V2 values
sections and some nonempty pages that exactly fill the destination
trigger the failure.
### What changes are included in this PR?
`brotliCodec.DecodeWithError` uses `io.ReadFull` for the extra byte
check, continuing past `(0, nil)` until a byte or an error arrives.
Reaching `io.EOF` succeeds. Extra decoded data still returns the
overflow error.
### Are these changes tested?
`TestBrotliDecodeDestinationSize` checks exact fill and the overflow
error. `TestReadAllNullBooleanDataPageV2Brotli` checks reading an all
null V2 page written with Brotli.
The exact fill assertion and the round trip fail on main and pass with
this change. The overflow assertion already passes on main. The cases in
the issue read as `rows=24575` and `rows=2 nulls=2` with this change.
With Go 1.26.10, vet, affected `-race -tags assert,test` tests, lint and
the Release Audit Tool passed.
### Are there any user-facing changes?
Yes. These Brotli pages decode successfully, including with default
writer properties. Other codecs and the public API are unchanged.
Closes https://github.com/apache/arrow-go/issues/1529.
---
parquet/compress/brotli.go | 3 ++-
parquet/compress/compress_test.go | 15 +++++++++++++++
parquet/pqarrow/encode_arrow_test.go | 25 +++++++++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/parquet/compress/brotli.go b/parquet/compress/brotli.go
index ca058ed1..32896273 100644
--- a/parquet/compress/brotli.go
+++ b/parquet/compress/brotli.go
@@ -131,8 +131,9 @@ func (brotliCodec) DecodeWithError(dst, src []byte)
([]byte, error) {
return nil, err
}
if sofar == len(dst) {
+ // Read can return (0, nil) on the call that finishes
the stream.
var extra [1]byte
- if n, err := rdr.Read(extra[:]); n != 0 || err !=
io.EOF {
+ if _, err := io.ReadFull(rdr, extra[:]); err != io.EOF {
if err != nil {
return nil, err
}
diff --git a/parquet/compress/compress_test.go
b/parquet/compress/compress_test.go
index 5fe8f867..7d86c5fd 100644
--- a/parquet/compress/compress_test.go
+++ b/parquet/compress/compress_test.go
@@ -259,6 +259,21 @@ func TestBrotliCompressBound(t *testing.T) {
}
}
+func TestBrotliDecodeDestinationSize(t *testing.T) {
+ codec, err := compress.GetCodec(compress.Codecs.Brotli)
+ assert.NoError(t, err)
+ // This stream is 32769 bytes, so the decoder's second 32 KiB read
holds only the final empty metablock.
+ data := makeRandomData(32765)
+ compressed := codec.Encode(nil, data)
+
+ out, err := compress.Decode(codec, make([]byte, len(data)), compressed)
+ assert.NoError(t, err)
+ assert.Equal(t, data, out)
+
+ _, err = compress.Decode(codec, make([]byte, len(data)-1), compressed)
+ assert.ErrorContains(t, err, "exceeds destination size")
+}
+
func TestBrotliEncodeLevelReuse(t *testing.T) {
codec, err := compress.GetCodec(compress.Codecs.Brotli)
assert.NoError(t, err)
diff --git a/parquet/pqarrow/encode_arrow_test.go
b/parquet/pqarrow/encode_arrow_test.go
index ab8d0797..2168a64e 100644
--- a/parquet/pqarrow/encode_arrow_test.go
+++ b/parquet/pqarrow/encode_arrow_test.go
@@ -769,6 +769,31 @@ func TestWriteAllNullsWithDeltaEncoding(t *testing.T) {
require.NoError(t, err)
}
+func TestReadAllNullBooleanDataPageV2Brotli(t *testing.T) {
+ sc := arrow.NewSchema([]arrow.Field{
+ {Name: "b", Type: arrow.FixedWidthTypes.Boolean, Nullable:
true},
+ }, nil)
+ rec, _, err := array.RecordFromJSON(memory.DefaultAllocator, sc,
strings.NewReader(`[{"b": null}, {"b": null}]`))
+ require.NoError(t, err)
+ defer rec.Release()
+
+ props := parquet.NewWriterProperties(
+ parquet.WithDataPageVersion(parquet.DataPageV2),
+ parquet.WithCompression(compress.Codecs.Brotli),
+ )
+ var buf bytes.Buffer
+ fw, err := pqarrow.NewFileWriter(sc, &buf, props,
pqarrow.DefaultWriterProps())
+ require.NoError(t, err)
+ require.NoError(t, fw.Write(rec))
+ require.NoError(t, fw.Close())
+
+ tbl, err := pqarrow.ReadTable(context.Background(),
bytes.NewReader(buf.Bytes()), nil, pqarrow.ArrowReadProperties{},
memory.DefaultAllocator)
+ require.NoError(t, err)
+ defer tbl.Release()
+ assert.EqualValues(t, 2, tbl.NumRows())
+ assert.Equal(t, 2, tbl.Column(0).NullN())
+}
+
func TestArrowReadWriteTableChunkedCols(t *testing.T) {
chunkSizes := []int{2, 4, 10, 2}
const totalLen = int64(18)