Skip to content

Commit a0152a7

Browse files
committed
Add a failing test when reading a value length at buffer boundary
1 parent 57ea2a0 commit a0152a7

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

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

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,35 @@ package org.msgpack.core
1717

1818
import java.io._
1919
import java.nio.ByteBuffer
20+
import java.nio.charset.StandardCharsets
2021

22+
import org.msgpack.core.MessageUnpackerTest.SplitMessageBufferInput
2123
import org.msgpack.core.buffer._
2224
import org.msgpack.value.ValueType
2325
import xerial.core.io.IOUtil
2426

2527
import scala.util.Random
2628

27-
/**
28-
* Created on 2014/05/07.
29-
*/
29+
object MessageUnpackerTest {
30+
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput {
31+
var cursor = 0
32+
override def next(): MessageBuffer = {
33+
if (cursor < array.length) {
34+
val a = array(cursor)
35+
cursor += 1
36+
MessageBuffer.wrap(a)
37+
}
38+
else {
39+
null
40+
}
41+
}
42+
43+
override def close(): Unit = {}
44+
}
45+
}
46+
47+
import MessageUnpackerTest._
48+
3049
class MessageUnpackerTest extends MessagePackSpec {
3150

3251
def testData: Array[Byte] = {
@@ -246,21 +265,6 @@ class MessageUnpackerTest extends MessagePackSpec {
246265

247266
}
248267

249-
class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput {
250-
var cursor = 0
251-
override def next(): MessageBuffer = {
252-
if (cursor < array.length) {
253-
val a = array(cursor)
254-
cursor += 1
255-
MessageBuffer.wrap(a)
256-
}
257-
else {
258-
null
259-
}
260-
}
261-
262-
override def close(): Unit = {}
263-
}
264268

265269
"read data at the buffer boundary" taggedAs ("boundary") in {
266270

@@ -703,5 +707,18 @@ class MessageUnpackerTest extends MessagePackSpec {
703707
Seq(8185, 8186, 8187, 8188, 16377, 16378, 16379, 16380).foreach { n => check(s, n)}
704708
}
705709
}
710+
711+
"read value length at buffer boundary" taggedAs("number-boundary") in {
712+
val input = new SplitMessageBufferInput(Array(
713+
Array[Byte](MessagePack.Code.STR16),
714+
Array[Byte](0x00),
715+
Array[Byte](0x05), // STR16 length at the boundary
716+
"hello".getBytes(MessagePack.UTF8))
717+
)
718+
val unpacker = MessagePack.newDefaultUnpacker(input)
719+
while(unpacker.hasNext) {
720+
unpacker.unpackValue()
721+
}
722+
}
706723
}
707724
}

0 commit comments

Comments
 (0)