Skip to content

Commit bb20326

Browse files
committed
Fixed deserialization of null/true/false/(u)int(16|32) (JSON) (shyiko#129)
1 parent 1612ebe commit bb20326

File tree

1 file changed

+26
-12
lines changed
  • src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json

1 file changed

+26
-12
lines changed

src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/json/JsonBinary.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ protected void parseObject(boolean small, JsonFormatter formatter)
322322
// Read the header ...
323323
int numElements = readUnsignedIndex(Integer.MAX_VALUE, small, "number of elements in");
324324
int numBytes = readUnsignedIndex(Integer.MAX_VALUE, small, "size of");
325+
int valueSize = small ? 2 : 4;
325326

326327
// Read each key-entry, consisting of the offset and length of each key ...
327328
int[] keyLengths = new int[numElements];
@@ -338,19 +339,25 @@ protected void parseObject(boolean small, JsonFormatter formatter)
338339
switch (type) {
339340
case LITERAL:
340341
entries[i] = new ValueEntry(type).setValue(readLiteral());
342+
reader.skip(valueSize - 1);
341343
break;
342344
case INT16:
345+
entries[i] = new ValueEntry(type).setValue(readInt16());
346+
reader.skip(valueSize - 2);
347+
break;
343348
case UINT16:
344-
// The "offset" is actually the value ...
345-
int value = readUnsignedIndex(Integer.MAX_VALUE, small, "value offset in");
346-
entries[i] = new ValueEntry(type).setValue(value);
349+
entries[i] = new ValueEntry(type).setValue(readUInt16());
350+
reader.skip(valueSize - 2);
347351
break;
348352
case INT32:
353+
if (!small) {
354+
entries[i] = new ValueEntry(type).setValue(readInt32());
355+
break;
356+
}
349357
case UINT32:
350358
if (!small) {
351-
// The value should be large enough to handle the actual value ...
352-
value = readUnsignedIndex(Integer.MAX_VALUE, small, "value offset in");
353-
entries[i] = new ValueEntry(type).setValue(value);
359+
entries[i] = new ValueEntry(type).setValue(readUInt32());
360+
break;
354361
}
355362
default:
356363
// It is an offset, not a value ...
@@ -459,6 +466,7 @@ protected void parseArray(boolean small, JsonFormatter formatter)
459466
// Read the header ...
460467
int numElements = readUnsignedIndex(Integer.MAX_VALUE, small, "number of elements in");
461468
int numBytes = readUnsignedIndex(Integer.MAX_VALUE, small, "size of");
469+
int valueSize = small ? 2 : 4;
462470

463471
// Read each key value value-entry
464472
ValueEntry[] entries = new ValueEntry[numElements];
@@ -468,19 +476,25 @@ protected void parseArray(boolean small, JsonFormatter formatter)
468476
switch (type) {
469477
case LITERAL:
470478
entries[i] = new ValueEntry(type).setValue(readLiteral());
479+
reader.skip(valueSize - 1);
471480
break;
472481
case INT16:
482+
entries[i] = new ValueEntry(type).setValue(readInt16());
483+
reader.skip(valueSize - 2);
484+
break;
473485
case UINT16:
474-
// The "offset" is actually the value ...
475-
int value = readUnsignedIndex(Integer.MAX_VALUE, small, "value offset in");
476-
entries[i] = new ValueEntry(type).setValue(value);
486+
entries[i] = new ValueEntry(type).setValue(readUInt16());
487+
reader.skip(valueSize - 2);
477488
break;
478489
case INT32:
490+
if (!small) {
491+
entries[i] = new ValueEntry(type).setValue(readInt32());
492+
break;
493+
}
479494
case UINT32:
480495
if (!small) {
481-
// The value should be large enough to handle the actual value ...
482-
value = readUnsignedIndex(Integer.MAX_VALUE, small, "value offset in");
483-
entries[i] = new ValueEntry(type).setValue(value);
496+
entries[i] = new ValueEntry(type).setValue(readUInt32());
497+
break;
484498
}
485499
default:
486500
// It is an offset, not a value ...

0 commit comments

Comments
 (0)