[common] Fix double position advance in DataOutputSerializer.writeBytes - #9520
Open
LuciferYang wants to merge 1 commit into
Open
[common] Fix double position advance in DataOutputSerializer.writeBytes#9520LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
writeBytes(String) wrote each byte through writeByte, which goes to write(int) and advances position itself, and then advanced 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 bytes. The sibling writeChars has the same shape and never had that line. Nothing in the repository calls this overload; it is part of the java.io.DataOutput contract that DataOutputView exposes, so the defect is visible to callers outside the repository. Assisted-by: GLM-5.3
Contributor
Author
|
The two |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
close #9519
DataOutputSerializer.writeBytes(String)wrote each byte throughwriteByte, which goes towrite(int)and doesthis.buffer[this.position++] = ..., and then advanced the position by the string length a second time. After the calllength()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, aresizefollowed by a loop ofwriteChar, 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,skipBytesToWriteandwrite(DataInputView, int)each advance by exactly the bytes they wrote.writeByteswas 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.DataOutputcontract thatDataOutputViewexposes, so the defect was visible to callers outside the repository.Tests
DataOutputSerializerTestis new; the class had no test before. All three assert ongetCopyOfBuffer(), which is cut atlength(), so each one pins the length and the content together.testWriteBytesAdvancesPositionOnce:writeBytes("abc")leaves exactlya b c.testWriteBytesLeavesTheNextWriteInPlace:writeBytes("abc")thenwriteInt(42)leavesa 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 teston JDK 8: 12467 tests, 0 failures, 0 errors. checkstyle, spotless, enforcer and rat run clean.