From 1612ebe3c21a248586500ae4f545bf33fff1d080 Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Sat, 19 Nov 2016 21:19:49 -0800 Subject: [PATCH] Fixed deserialization of variable-length data types (JSON) (#129) --- .../event/deserialization/json/JsonBinary.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java index 916c8b99..4fe174b4 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java @@ -934,13 +934,15 @@ protected BigInteger readUInt64() throws IOException { * @return the integer value */ protected int readVariableInt() throws IOException { - byte b = 0; int length = 0; - do { - b = (byte) reader.read(); - length = (length << 7) + (b & 0x7F); - } while (b < 0); - return length; + for (int i = 0; i < 5; i++) { + byte b = (byte) reader.read(); + length |= (b & 0x7F) << (7 * i); + if ((b & 0x80) == 0) { + return length; + } + } + throw new IOException("Unexpected byte sequence (" + length + ")"); } protected Boolean readLiteral() throws IOException {