diff --git a/src/main/java/io/asyncer/r2dbc/mysql/internal/util/VarIntUtils.java b/src/main/java/io/asyncer/r2dbc/mysql/internal/util/VarIntUtils.java index c5a4d530a..dba99fd72 100644 --- a/src/main/java/io/asyncer/r2dbc/mysql/internal/util/VarIntUtils.java +++ b/src/main/java/io/asyncer/r2dbc/mysql/internal/util/VarIntUtils.java @@ -47,6 +47,17 @@ public final class VarIntUtils { private static final int MEDIUM_SIZE = MEDIUM_BYTES * Byte.SIZE; + /** + * Reads a length encoded integer from the given buffers. Notice that a length encoded integer can be + * greater than {@link Long#MAX_VALUE}. In this case it should be used as an unsigned long. If we need + * assume the result as a smaller integer, add code comment to explain it. + *
+ * Note: it will change {@code firstPart} and {@code secondPart} readerIndex if necessary. + * + * @param firstPart the first part of a readable buffer include a part of the var integer. + * @param secondPart the second part of a readable buffer include subsequent part of the var integer. + * @return A var integer read from buffer. + */ public static long crossReadVarInt(ByteBuf firstPart, ByteBuf secondPart) { requireNonNull(firstPart, "firstPart must not be null"); requireNonNull(secondPart, "secondPart must not be null"); @@ -87,6 +98,10 @@ public static long crossReadVarInt(ByteBuf firstPart, ByteBuf secondPart) { } /** + * Reads a length encoded integer from the given buffer. Notice that a length encoded integer can be + * greater than {@link Long#MAX_VALUE}. In this case it should be used as an unsigned long. If we need + * assume the result as a smaller integer, add code comment to explain it. + *
* Note: it will change {@code buf} readerIndex.
*
* @param buf a readable buffer include a var integer.
diff --git a/src/main/java/io/asyncer/r2dbc/mysql/message/server/ColumnCountMessage.java b/src/main/java/io/asyncer/r2dbc/mysql/message/server/ColumnCountMessage.java
index a036e7a25..a23019a1f 100644
--- a/src/main/java/io/asyncer/r2dbc/mysql/message/server/ColumnCountMessage.java
+++ b/src/main/java/io/asyncer/r2dbc/mysql/message/server/ColumnCountMessage.java
@@ -40,6 +40,7 @@ public int getTotalColumns() {
}
static ColumnCountMessage decode(ByteBuf buf) {
+ // JVM does NOT support arrays longer than Integer.MAX_VALUE
return new ColumnCountMessage(Math.toIntExact(VarIntUtils.readVarInt(buf)));
}
diff --git a/src/main/java/io/asyncer/r2dbc/mysql/message/server/DefinitionMetadataMessage.java b/src/main/java/io/asyncer/r2dbc/mysql/message/server/DefinitionMetadataMessage.java
index 3fb4950ab..a2aac7a8b 100644
--- a/src/main/java/io/asyncer/r2dbc/mysql/message/server/DefinitionMetadataMessage.java
+++ b/src/main/java/io/asyncer/r2dbc/mysql/message/server/DefinitionMetadataMessage.java
@@ -173,7 +173,8 @@ private static DefinitionMetadataMessage decode41(ByteBuf buf, ConnectionContext
String column = readVarIntSizedString(buf, charset);
String originColumn = readVarIntSizedString(buf, charset);
- VarIntUtils.readVarInt(buf); // skip constant 0x0c encoded by var integer
+ // Skip constant 0x0c encoded by var integer
+ VarIntUtils.readVarInt(buf);
int collationId = buf.readUnsignedShortLE();
long size = buf.readUnsignedIntLE();
@@ -185,7 +186,7 @@ private static DefinitionMetadataMessage decode41(ByteBuf buf, ConnectionContext
}
private static String readVarIntSizedString(ByteBuf buf, Charset charset) {
- // JVM can NOT support string which length upper than maximum of int32
+ // JVM does NOT support strings longer than Integer.MAX_VALUE
int bytes = (int) VarIntUtils.readVarInt(buf);
if (bytes == 0) {
diff --git a/src/main/java/io/asyncer/r2dbc/mysql/message/server/LargeFieldReader.java b/src/main/java/io/asyncer/r2dbc/mysql/message/server/LargeFieldReader.java
index 3eb133aac..9842687b1 100644
--- a/src/main/java/io/asyncer/r2dbc/mysql/message/server/LargeFieldReader.java
+++ b/src/main/java/io/asyncer/r2dbc/mysql/message/server/LargeFieldReader.java
@@ -99,12 +99,12 @@ public FieldValue readVarIntSizedField() {
fieldSize = VarIntUtils.readVarInt(currentBuf);
}
- // Refresh non empty buffer because current buffer has been read.
+ // Refresh non-empty buffer because current buffer has been read.
currentBuf = nonEmptyBuffer();
List