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 f0a52726 fix(parquet/file): widen the page writer ordinal to int32
(#1571)
f0a52726 is described below
commit f0a52726cfb0c99428cf23af9148a1df4a61dcb0
Author: Ayaan <[email protected]>
AuthorDate: Tue Nov 17 00:09:42 2026 +0530
fix(parquet/file): widen the page writer ordinal to int32 (#1571)
### Rationale for this change
Fixes #1538. `pageOrdinal` in `serializedPageWriter` is an `int16`, so
it wraps back to 0 after 65,536 data pages in a column chunk.
The writer then saves a later page's position as `data_page_offset`. The
reader starts at the wrong page, which causes `ReadTable` to hit EOF in
the issue's repro.
### What changes are included in this PR?
Changed `pageOrdinal` to `int32`, matching Arrow C++.
Encryption AAD still uses an `int16` page ordinal. The writer now
returns an error before writing a data page with an ordinal above
32,767, instead of letting it wrap silently. This allows 32,768 data
pages per encrypted chunk.
The check matches C++ `CheckPageOrdinal` and parquet-java, and uses the
same error wording as C++.
The reader's `pageOrd` is unchanged. I asked on the issue whether that
should be included here or handled in a follow-up.
### Are these changes tested?
Yes, with two tests:
- Write 65,537 pages to a discard sink and check that `data_page_offset`
still points to the first page. This fails on main.
- Start an encrypted writer at ordinal 32,767. That page writes
successfully, and the next page returns an error.
`go test ./parquet/...` passes with no tags, `-tags assert`, and `-tags
assert,noasm`, with `PARQUET_TEST_DATA` set.
### Are there any user-facing changes?
Unencrypted column chunks with more than 65,536 data pages now work
without corrupting the file.
Encrypted chunks now return an error after 32,768 data pages instead of
silently wrapping.
---
parquet/file/page_writer.go | 9 +++--
parquet/file/page_writer_internal_test.go | 62 +++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/parquet/file/page_writer.go b/parquet/file/page_writer.go
index 59de1322..cb754c6c 100644
--- a/parquet/file/page_writer.go
+++ b/parquet/file/page_writer.go
@@ -68,7 +68,7 @@ type serializedPageWriter struct {
dataPageOffset int64
totalUncompressed int64
totalCompressed int64
- pageOrdinal int16
+ pageOrdinal int32
rgOrdinal int16
columnOrdinal int16
@@ -184,14 +184,17 @@ func (pw *serializedPageWriter) initEncryption() {
}
func (pw *serializedPageWriter) updateEncryption(moduleType int8) error {
+ if (moduleType == encryption.DataPageModule || moduleType ==
encryption.DataPageHeaderModule) && pw.pageOrdinal > math.MaxInt16 {
+ return fmt.Errorf("parquet: encrypted parquet files cannot have
more than %d pages per chunk: got %d", math.MaxInt16, pw.pageOrdinal)
+ }
switch moduleType {
case encryption.ColumnMetaModule:
pw.metaEncryptor.UpdateAad(encryption.CreateModuleAad(pw.metaEncryptor.FileAad(),
moduleType, pw.rgOrdinal, pw.columnOrdinal, -1))
case encryption.DataPageModule:
- encryption.QuickUpdatePageAad(pw.dataPageAAD, pw.pageOrdinal)
+ encryption.QuickUpdatePageAad(pw.dataPageAAD,
int16(pw.pageOrdinal))
pw.dataEncryptor.UpdateAad(string(pw.dataPageAAD))
case encryption.DataPageHeaderModule:
- encryption.QuickUpdatePageAad(pw.dataPageHeaderAAD,
pw.pageOrdinal)
+ encryption.QuickUpdatePageAad(pw.dataPageHeaderAAD,
int16(pw.pageOrdinal))
pw.metaEncryptor.UpdateAad(string(pw.dataPageHeaderAAD))
case encryption.DictPageHeaderModule:
pw.metaEncryptor.UpdateAad(encryption.CreateModuleAad(pw.metaEncryptor.FileAad(),
moduleType, pw.rgOrdinal, pw.columnOrdinal, -1))
diff --git a/parquet/file/page_writer_internal_test.go
b/parquet/file/page_writer_internal_test.go
index 38c5a236..087617f3 100644
--- a/parquet/file/page_writer_internal_test.go
+++ b/parquet/file/page_writer_internal_test.go
@@ -20,11 +20,13 @@ import (
"bytes"
"errors"
"io"
+ "math"
"testing"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/apache/arrow-go/v18/parquet"
"github.com/apache/arrow-go/v18/parquet/compress"
+ "github.com/apache/arrow-go/v18/parquet/internal/encryption"
"github.com/stretchr/testify/require"
)
@@ -107,3 +109,63 @@ func TestSerializedPageWriterRejectsShortWrites(t
*testing.T) {
})
}
}
+
+type discardTellSink struct {
+ pos int64
+}
+
+func (s *discardTellSink) Tell() int64 { return s.pos }
+func (s *discardTellSink) Write(p []byte) (int, error) {
+ s.pos += int64(len(p))
+ return len(p), nil
+}
+
+func TestSerializedPageWriterDataPageOffsetPageOrdinalWrap(t *testing.T) {
+ sink := &discardTellSink{pos: 4}
+ writer, err := NewPageWriter(sink, compress.Codecs.Uncompressed,
+ compress.DefaultCompressionLevel, nil, -1, -1,
memory.DefaultAllocator, false, nil, nil)
+ require.NoError(t, err)
+
+ buf := memory.NewBufferBytes([]byte("page body"))
+ defer buf.Release()
+
+ page := NewDataPageV1(buf, 1, parquet.Encodings.Plain,
+ parquet.Encodings.RLE, parquet.Encodings.RLE, int32(buf.Len()))
+
+ for i := 0; i < 65537; i++ {
+ _, err := writer.WriteDataPage(page)
+ require.NoError(t, err)
+ }
+
+ serialized := writer.(*serializedPageWriter)
+ require.Equal(t, int64(4), serialized.DataPageoffset())
+ require.Equal(t, int32(65537), serialized.pageOrdinal)
+}
+
+func TestSerializedPageWriterEncryptionRejectsMoreThanMaxInt16Pages(t
*testing.T) {
+ const key = "0123456789012345"
+ encProps := parquet.NewFileEncryptionProperties(key)
+ fileEnc := encryption.NewFileEncryptor(encProps,
memory.DefaultAllocator)
+
+ sink := &discardTellSink{pos: 4}
+ writer, err := NewPageWriter(sink, compress.Codecs.Uncompressed,
+ compress.DefaultCompressionLevel, nil, 0, 0,
memory.DefaultAllocator, false,
+ fileEnc.GetColumnMetaEncryptor("col"),
fileEnc.GetColumnDataEncryptor("col"))
+ require.NoError(t, err)
+
+ serialized := writer.(*serializedPageWriter)
+ serialized.pageOrdinal = math.MaxInt16
+
+ buf := memory.NewBufferBytes([]byte("page body"))
+ defer buf.Release()
+ page := NewDataPageV1(buf, 1, parquet.Encodings.Plain,
+ parquet.Encodings.RLE, parquet.Encodings.RLE, int32(buf.Len()))
+
+ _, err = writer.WriteDataPage(page)
+ require.NoError(t, err)
+ require.Equal(t, int32(math.MaxInt16+1), serialized.pageOrdinal)
+
+ _, err = writer.WriteDataPage(page)
+ require.Error(t, err)
+ require.Contains(t, err.Error(), "encrypted parquet files cannot have
more than 32767 pages per chunk")
+}