HarshDevelops opened a new pull request, #3878:
URL: https://github.com/apache/avro/pull/3878

   Closes AVRO-4268
   
   ### Summary
   `AvroDatumConverterFactory.BytesWritableConverter#convert(BytesWritable)`
   calls `ByteBuffer.wrap(input.getBytes())`, which wraps the **backing array**.
   `BytesWritable.getBytes()` can be longer than the value's logical length
   (`BytesWritable.getLength()`). The converter was therefore serialising stale
   or unused capacity bytes into Avro `bytes`.
   
   This change wraps `input.getBytes()` with the actual length, so the
   serialised value is exactly the caller's data.
   
   ### Diff
   
   ```diff
   --- 
a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroDatumConverterFactory.java
   +++ 
b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroDatumConverterFactory.java
   @@
        @Override
        public ByteBuffer convert(BytesWritable input) {
   -      return ByteBuffer.wrap(input.getBytes());
   +      return ByteBuffer.wrap(input.getBytes(), 0, input.getLength());
        }
   ```
   
   ### Tests
   - Added `convertBytesWritableRespectsLogicalLength` in
     `TestAvroDatumConverterFactory`. With the unfixed code it fails with
     `expected: <3> but was: <5>`; with the fix it passes.
   - Full `lang/java/mapred` module suite:
     `Tests run: 110, Failures: 0, Errors: 0, Skipped: 0`.
   
   ### Notes
   - The fix is zero-allocation (no `copyBytes()` alternative).
   - `mvn spotless:apply` was used to normalise the test file's whitespace;
     no unrelated changes were included.
   
   ### Sign-off
   
   Signed-off-by: Harsh Srivastava <[email protected]>
   
   I have an ICLA on file with the ASF; please let me know if anything else
   is needed on the Apache side.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to