Visitar URL original
core (fix): Fix MessageUnpacker.unpackValue to check the custom stringSizeLimit by xerial · Pull Request #753 · msgpack/msgpack-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
core (fix): Fix MessageUnpacker.unpackValue to check the custom strin…
…gSizeLimit
  • Loading branch information
xerial committed Jul 31, 2023
commit 59c68e10216036875e2dae3eecf39a8668694d05
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ public ImmutableValue unpackValue()
return ValueFactory.newFloat(unpackDouble());
case STRING: {
int length = unpackRawStringHeader();
if (length > stringSizeLimit) {
throw new MessageSizeException(String.format("cannot unpack a String of size larger than %,d: %,d", stringSizeLimit, length), length);
}
return ValueFactory.newString(readPayload(length), true);
}
case BINARY: {
Expand Down
28 changes: 28 additions & 0 deletions msgpack-core/src/test/scala/org/msgpack/core/StringLimitTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.msgpack.core

import org.msgpack.core.MessagePack.UnpackerConfig
import wvlet.airspec.AirSpec

class StringLimitTest extends AirSpec {

test("throws an exception when the string size exceeds a limit") {
val customLimit = 100
val packer = MessagePack.newDefaultBufferPacker()
packer.packString("a" * (customLimit + 1))
val msgpack = packer.toByteArray

test("unpackString") {
val unpacker = new UnpackerConfig().withStringSizeLimit(customLimit).newUnpacker(msgpack)
intercept[MessageSizeException] {
unpacker.unpackString()
}
}

test("unpackValue") {
val unpacker = new UnpackerConfig().withStringSizeLimit(customLimit).newUnpacker(msgpack)
intercept[MessageSizeException] {
unpacker.unpackValue()
}
}
}
}