FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix MessageUnpacker#unpackString in case that string length is more than... by komamitsu · Pull Request #215 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) .scala  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ public String unpackString() throws IOException {

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

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

decodeBuffer.clear();
cursor += readLen;
consume(readLen);
}

cursor += readLen;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think there is no guarantee that the read length from the input always matches Math.min(buffer.size() - position, strLen-cursor) when OVERFLOW (output buffer has insufficient space) happens. When OVERFLOW occurs, the input data might be partially read. That is why I compute readLen as bb.limit() - bb.remaining().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah. I was wrong. readLen can be retrieved by bb.position() since we created a new ByteBuffer at

ByteBuffer bb = buffer.toByteBuffer(position, readLen);

whose initial position is 0.

consume(readLen);
}

return sb.toString();
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -618,5 +618,33 @@ class MessageUnpackerTest extends MessagePackSpec {
checkFile(u)
u.close
}

"parse message large packed data" taggedAs("unpack") in {
def createLargeData(stringLength: Int): Array[Byte] = {
val out = new ByteArrayOutputStream()
val packer = msgpack.newPacker(out)

packer
.packArrayHeader(2)
.packString("l" * stringLength)
.packInt(1)

packer.close()

out.toByteArray
}

Seq(8191, 8192, 8193, 16383, 16384, 16385).foreach { n =>
val arr = createLargeData(n)

val unpacker = msgpack.newUnpacker(arr)

unpacker.unpackArrayHeader shouldBe 2
unpacker.unpackString.length shouldBe n
unpacker.unpackInt shouldBe 1

unpacker.getTotalReadBytes shouldBe arr.length
}
}
}
}

Back | FazBrowse Home | New Git URL