Skip to content

fix(parquet/variant): return "" for an empty long-form string - #1353

Merged
zeroshade merged 1 commit into
apache:mainfrom
CaptainAni187:fix/variant-empty-long-string-1344
Oct 6, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
CaptainAni187:fix/variant-empty-long-string-1344

Conversation

@CaptainAni187

Copy link
Copy Markdown

Rationale for this change

Fixes #1344. Value.Value() built a long-form string with unsafe.String(&v.value[5], sz). For an empty string the encoded value is only the 5-byte header and length, so &v.value[5] was out of range and it panicked. String() and MarshalJSON() go through Value() and panicked the same way. validatePrimitiveValue accepts the encoding, so variant.New returns the value without an error.

What changes are included in this PR?

The PrimitiveString branch now returns "" when the length is zero, the same guard the short-string branch already has.

Are these changes tested?

Yes. TestLongFormString builds the 5-byte encoding from the issue and a non-empty long-form string, and checks Type(), Value() and String() for both. The empty case panics on main with index out of range [5] with length 5 and passes with the fix.

go test ./parquet/... passes (with the testing submodules), as do the other packages that import parquet/variant (arrow/compute, arrow/extensions, parquet/pqarrow). golangci-lint v2.13.2 reports no issues.

Are there any user-facing changes?

An empty string in the long-form encoding now reads as "" instead of panicking.

Value() built a long-form string with unsafe.String(&v.value[5], sz). For an
empty string the encoded value is only the 5-byte header and length, so
&v.value[5] was out of range and Value() panicked, and String() and
MarshalJSON() with it. validatePrimitiveValue accepts the encoding, so the
value comes back from variant.New without an error.

Guard it the way the short-string branch already does, and add a test for
the empty and non-empty long forms.

Fixes #1344

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. The guard mirrors the short-string branch, and I confirmed the new test panics on main (index out of range [5] with length 5) and passes here; the full parquet/variant suite is green. The sibling PrimitiveBinary branch is already safe for a zero length (v.value[5:5]), so nothing else needs the same treatment. LGTM.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Arrow handles maintainer review:
CONTRIBUTING.md.

@zeroshade
zeroshade merged commit 5fb2a20 into apache:main Oct 6, 2026
36 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Parquet] Variant Value() panics on an empty long-form string

2 participants