Skip to content

fix: ValueWriters.FixedByteBufferWriter should use writeFixed(), not writeBytes() [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #17507

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/iceberg-17501-fixedbytebuffer-writefixed
Open

fix: ValueWriters.FixedByteBufferWriter should use writeFixed(), not writeBytes() [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]#17507
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/iceberg-17501-fixedbytebuffer-writefixed

Conversation

@waterWang

Copy link
Copy Markdown

Description

For Avro fixed[N] fields, the encoder must write fixed-length data
without a length prefix. writeBytes() writes a length-prefixed bytes
value, which corrupts the Avro binary encoding for fixed[N] schema.

Fix

Replace encoder.writeBytes(bytes) with the correct fixed-length write:

byte[] arr = new byte[length];
bytes.duplicate().get(arr);
encoder.writeFixed(arr, 0, length);

Testing

  • The Preconditions.checkArgument validates bytes.remaining() == length before the write
  • duplicate() creates a view so the original buffer's position is not modified
  • All existing tests should pass (the fix only changes the Avro encoding method, not the data)

Fixes #17501

@github-actions github-actions Bot added the core label Aug 4, 2026

@uros-b uros-b 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.

@waterWang Please note that this may have already been covered in #17502. cc @DuanRuixiao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: ValueWriters.FixedByteBufferWriter uses writeBytes() instead of writeFixed() for Avro fixed[N] fields

2 participants