Skip to content

Commit 25fc565

Browse files
committed
Fix MessageUnpacker#unpackString in case that string length is more than 8192
1 parent 70e4407 commit 25fc565

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,6 @@ public String unpackString() throws IOException {
980980

981981
if(cr.isOverflow()) {
982982
// The output CharBuffer has insufficient space
983-
readLen = bb.limit() - bb.remaining();
984983
decoder.reset();
985984
}
986985

@@ -1005,9 +1004,10 @@ public String unpackString() throws IOException {
10051004
sb.append(decodeBuffer);
10061005

10071006
decodeBuffer.clear();
1008-
cursor += readLen;
1009-
consume(readLen);
10101007
}
1008+
1009+
cursor += readLen;
1010+
consume(readLen);
10111011
}
10121012

10131013
return sb.toString();

msgpack-core/src/test/scala/org/msgpack/core/MessageUnpackerTest.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,33 @@ class MessageUnpackerTest extends MessagePackSpec {
618618
checkFile(u)
619619
u.close
620620
}
621+
622+
"parse message large packed data" taggedAs("unpack") in {
623+
def createLargeData(stringLength: Int): Array[Byte] = {
624+
val out = new ByteArrayOutputStream()
625+
val packer = msgpack.newPacker(out)
626+
627+
packer
628+
.packArrayHeader(2)
629+
.packString("l" * stringLength)
630+
.packInt(1)
631+
632+
packer.close()
633+
634+
out.toByteArray
635+
}
636+
637+
Seq(8191, 8192, 8193, 16383, 16384, 16385).foreach { n =>
638+
val arr = createLargeData(n)
639+
640+
val unpacker = msgpack.newUnpacker(arr)
641+
642+
unpacker.unpackArrayHeader shouldBe 2
643+
unpacker.unpackString.length shouldBe n
644+
unpacker.unpackInt shouldBe 1
645+
646+
unpacker.getTotalReadBytes shouldBe arr.length
647+
}
648+
}
621649
}
622650
}

0 commit comments

Comments
 (0)