Skip to content

GH-3471: Fix ByteBuffer handling in VariantUtil and VariantBuilder#3472

Open
rayokota wants to merge 1 commit intoapache:masterfrom
rayokota:fix-variant
Open

GH-3471: Fix ByteBuffer handling in VariantUtil and VariantBuilder#3472
rayokota wants to merge 1 commit intoapache:masterfrom
rayokota:fix-variant

Conversation

@rayokota
Copy link
Copy Markdown

@rayokota rayokota commented Apr 11, 2026

Rationale for this change

Fix ByteBuffer handling in VariantUtil and VariantBuilder.

What changes are included in this PR?

  • Fix VariantUtil.getMetadataMap reading string bytes from the wrong position
    when the metadata ByteBuffer has a non-zero position(). Changed
    slice(metadata, stringStart + offset) to
    slice(metadata, pos + stringStart + offset) to match the array-backed branch.
  • Fix VariantBuilder.appendBinary mutating the caller's ByteBuffer by using
    binary.duplicate(), consistent with appendEncodedValue.

Are these changes tested?

  • Added TestVariantObject.testMetadataWithNonZeroPositionReadOnly: constructs a
    metadata ByteBuffer with a non-zero position and read-only flag, then verifies
    ImmutableMetadata (which calls getMetadataMap) correctly parses the
    dictionary. Fails without the fix.
  • Added TestVariantScalarBuilder.testBinaryBuilderDoesNotMutateCallerBuffer:
    verifies that appendBinary does not change the caller's ByteBuffer position
    or remaining count.

Are there any user-facing changes?

  • No

Closes #3471

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.

VariantUtil.getMetadataMap reads from wrong position for non-array ByteBuffer; VariantBuilder.appendBinary mutates caller's ByteBuffer

1 participant