Skip to content

AVRO-4268: BytesWritableConverter should respect logical length - #3878

Merged
RyanSkraba merged 1 commit into
apache:mainfrom
HarshDevelops:fix/AVRO-4268-bytes-writable-length
Jul 19, 2026
Merged

AVRO-4268: BytesWritableConverter should respect logical length#3878
RyanSkraba merged 1 commit into
apache:mainfrom
HarshDevelops:fix/AVRO-4268-bytes-writable-length

Conversation

@HarshDevelops

@HarshDevelops HarshDevelops commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Closes AVRO-4268

What was wrong

BytesWritable can use a backing array that is larger than the value it
currently contains. The converter used the entire backing array, so unused
bytes could be included in the Avro value.

What changed

The converter now uses BytesWritable.getLength() and includes only the
bytes that belong to the current value.

A regression test covers a five-byte backing array whose logical value is only
three bytes.

Testing

  • Regression test: 1 passed, 0 failed, 0 errors, 0 skipped
  • lang/java/mapred suite: 110 passed, 0 failed, 0 errors, 0 skipped
  • Spotless check passed
  • git diff --check passed

The commit is signed off using harsh10822@gmail.com. Please let me know if
any ASF CLA action is required.

BytesWritable.getBytes() returns the backing array, which can be larger
than the logical length reported by BytesWritable.getLength(). Wrap
input.getBytes() with the actual length so the Avro bytes value reflects
the caller's data, not unused backing-array capacity.

Adds convertBytesWritableRespectsLogicalLength to cover the regression.

Signed-off-by: Harsh Srivastava <harsh10822@gmail.com>
@github-actions github-actions Bot added the Java Pull Requests for Java binding label Jul 19, 2026

@RyanSkraba RyanSkraba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@RyanSkraba
RyanSkraba merged commit f3bb10e into apache:main Jul 19, 2026
9 checks passed
RyanSkraba pushed a commit that referenced this pull request Jul 19, 2026
BytesWritable.getBytes() returns the backing array, which can be larger
than the logical length reported by BytesWritable.getLength(). Wrap
input.getBytes() with the actual length so the Avro bytes value reflects
the caller's data, not unused backing-array capacity.

Adds convertBytesWritableRespectsLogicalLength to cover the regression.

Signed-off-by: Harsh Srivastava <harsh10822@gmail.com>
@RyanSkraba

Copy link
Copy Markdown
Contributor

Cherry-picked to branch-1.12.

We don't require a CLA, but if you'd like credit in our bug tracker, don't hesitate to create an account and we'll assign it to you! https://issues.apache.org/jira/browse/AVRO-4268 Thanks again for the fix.

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

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants