Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-1035] correcting double write of buffer when writing ascii data…
… in case of growing packet buffer
  • Loading branch information
rusher committed Dec 21, 2022
1 parent db23815 commit 7399a26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -347,6 +347,7 @@ public void writeAscii(String str) throws IOException {
if (len > buf.length - pos) {
byte[] arr = str.getBytes(StandardCharsets.US_ASCII);
writeBytes(arr, 0, arr.length);
return;
}
for (int off = 0; off < len; ) {
this.buf[this.pos++] = (byte) str.charAt(off++);
Expand Down
@@ -0,0 +1,25 @@
package org.mariadb.jdbc.unit.client.socket;

import java.io.IOException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mariadb.jdbc.client.socket.impl.PacketWriter;

public class PackerWriterTest {

This comment has been minimized.

Copy link
@ffdybuster

ffdybuster Dec 23, 2022

@rusher might make sense to fix the typo (Packer) in the class name so the test is easier to find :)

This comment has been minimized.

Copy link
@rusher

rusher Jan 13, 2023

Author Collaborator

@ffdybuster good point, done in another commit : 80ef974


@Test
public void growBuffer() throws IOException {
PacketWriter pw = new PacketWriter(null, 0, 0xffffff, null, null);
Assertions.assertEquals(4, pw.pos());
pw.writeBytes(new byte[8190], 0, 8190);
pw.writeAscii("abcdefghij");
Assertions.assertEquals(8200, pw.pos() - 4);

for (int i = 0; i < 8190; i++) {
Assertions.assertEquals(0, pw.buf()[i + 4]);
}
for (int i = 0; i < 10; i++) {
Assertions.assertEquals('a' + i, pw.buf()[i + 8194]);
}
}
}

0 comments on commit 7399a26

Please sign in to comment.