Skip to content

fix: use writeFixed instead of writeBytes for FixedByteBufferWriter - #17505

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/fixed-byte-buffer-writer-writefixed
Open

fix: use writeFixed instead of writeBytes for FixedByteBufferWriter#17505
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix/fixed-byte-buffer-writer-writefixed

Conversation

@waterWang

Copy link
Copy Markdown

Bug fix: FixedByteBufferWriter uses writeBytes instead of writeFixed for Avro fixed[N] fields

Fixes #17501

Problem

ValueWriters.FixedByteBufferWriter.write(ByteBuffer, Encoder) calls encoder.writeBytes(bytes) instead of encoder.writeFixed(bytes). For Avro fixed[N] fields this is wrong: writeBytes prepends a zigzag-encoded length prefix before the data, but the Avro reader consumes exactly N bytes for a fixed field and has no length prefix to skip. The stray prefix byte spills into the next field in the record.

Fix

Convert the ByteBuffer to a byte[] and call encoder.writeFixed(arr) instead.

Testing

Existing tests for fixed[N] fields with ByteBuffer values should now pass without corruption. The sibling class FixedWriter (which handles byte[]) already uses writeFixed correctly.

@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