LuciferYang opened a new pull request, #9520:
URL: https://github.com/apache/paimon/pull/9520
### Purpose
close #9519
`DataOutputSerializer.writeBytes(String)` wrote each byte through
`writeByte`, which goes to `write(int)` and does `this.buffer[this.position++]
= ...`, and then advanced the position by the string length a second time.
After the call `length()` reported twice the bytes written, and the next write
landed past a gap of untouched buffer, so the serialized output was longer than
the data and carried whatever the array happened to hold. Removing the extra
advance is the whole change.
The sibling `writeChars(String)` has the same shape, a `resize` followed by
a loop of `writeChar`, and never had that line, which is the form this method
should have had.
I audited every position update in the class while checking this:
`write(byte[], int, int)`, `write(MemorySegment, int, int)`, `writeChar`,
`writeShort`, `writeInt`, `writeLong`, `writeUTF`, `skipBytesToWrite` and
`write(DataInputView, int)` each advance by exactly the bytes they wrote.
`writeBytes` was the only one that did not.
Nothing in the repository calls this overload, so no Paimon code path
changes behavior. It is part of the `java.io.DataOutput` contract that
`DataOutputView` exposes, so the defect was visible to callers outside the
repository.
### Tests
`DataOutputSerializerTest` is new; the class had no test before. All three
assert on `getCopyOfBuffer()`, which is cut at `length()`, so each one pins the
length and the content together.
- `testWriteBytesAdvancesPositionOnce`: `writeBytes("abc")` leaves exactly
`a b c`.
- `testWriteBytesLeavesTheNextWriteInPlace`: `writeBytes("abc")` then
`writeInt(42)` leaves `a b c 0 0 0 42`, which is the assertion that catches a
gap rather than just a wrong length.
- `testWriteBytesAcrossAResize`: starts from a two-byte buffer and writes
six bytes, so the growth path runs during the call.
All three fail against the pre-fix code.
`mvn -pl paimon-common test` on JDK 8: 12467 tests, 0 failures, 0 errors.
checkstyle, spotless, enforcer and rat run clean.
--
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]