Skip to content

[Bug] DataOutputSerializer.writeBytes advances the write position twice #9519

Description

@LuciferYang

Search before asking

  • I searched in the issues and found nothing similar.

Paimon version

master, 9c7deebbd (2.1-SNAPSHOT)

Compute Engine

Java API. DataOutputSerializer implements DataOutputView, which extends java.io.DataOutput.

Minimal reproduce step

writeBytes(String) writes each byte through writeByte, which goes to write(int):

public void write(int b) throws IOException {
    if (this.position >= this.buffer.length) {
        resize(1);
    }
    this.buffer[this.position++] = (byte) (b & 0xff);
}

so the position is already advanced per byte. The method then advanced it again by the string length:

for (int i = 0; i < sLen; i++) {
    writeByte(s.charAt(i));
}
this.position += sLen;
DataOutputSerializer out = new DataOutputSerializer(16);
out.writeBytes("abc");
out.length();            // 6, should be 3
out.writeInt(42);
out.length();            // 10, and bytes 3..5 were never written

What doesn't meet your expectations?

After writeBytes, length() reports twice the bytes written and every later write lands past a gap of untouched buffer, so the serialized output is longer than the data and carries whatever was in the array. The sibling writeChars(String) has the same shape, a resize followed by a loop of writeChar, and never had the extra advance, which is the intended form.

Nothing in the repository calls this overload, so no Paimon code path is affected today. It is reachable for anyone holding a DataOutputView or DataOutput, which is the contract the class implements.

Anything else?

I audited the rest of the class: write(byte[], int, int), write(MemorySegment, int, int), writeChar, writeShort, writeInt, writeLong, writeUTF, skipBytesToWrite and write(DataInputView, int) all advance the position by exactly the bytes they wrote. writeBytes is the only one that does not.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions