Skip to content

Commit 907cfed

Browse files
committed
Fixed upperbound and lower bound of IntAccept#acceptInteger(long).
Signed-off-by: Tsuyoshi Ozawa <ozawa.tsuyoshi@gmail.com>
1 parent 25f3c3d commit 907cfed

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/main/java/org/msgpack/unpacker/IntAccept.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void acceptInteger(int v) {
4343

4444
@Override
4545
void acceptInteger(long v) {
46-
if (value < (long) Integer.MIN_VALUE || value > (long) Integer.MAX_VALUE) {
46+
if (v < (long) Integer.MIN_VALUE || v > (long) Integer.MAX_VALUE) {
4747
throw new MessageTypeException(); // TODO message
4848
}
4949
this.value = (int) v;

src/test/java/org/msgpack/TestPackUnpack.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,34 @@ public void testLong(long v) throws Exception {
119119
assertEquals(bytes.length, unpacker.getReadByteCount());
120120
}
121121

122+
@Test(expected=MessageTypeException.class)
123+
public void testReadIntOverUpperBound() throws Exception {
124+
long v = Integer.MAX_VALUE + 1L;
125+
MessagePack msgpack = new MessagePack();
126+
ByteArrayOutputStream out = new ByteArrayOutputStream();
127+
Packer packer = msgpack.createPacker(out);
128+
packer.write(v);
129+
byte[] bytes = out.toByteArray();
130+
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
131+
Unpacker unpacker = msgpack.createUnpacker(in);
132+
unpacker.resetReadByteCount();
133+
unpacker.readInt();
134+
}
135+
136+
@Test(expected=MessageTypeException.class)
137+
public void testReadIntUnderLowerBound() throws Exception {
138+
long v = Integer.MIN_VALUE - 1L;
139+
MessagePack msgpack = new MessagePack();
140+
ByteArrayOutputStream out = new ByteArrayOutputStream();
141+
Packer packer = msgpack.createPacker(out);
142+
packer.write(v);
143+
byte[] bytes = out.toByteArray();
144+
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
145+
Unpacker unpacker = msgpack.createUnpacker(in);
146+
unpacker.resetReadByteCount();
147+
unpacker.readInt();
148+
}
149+
122150
@Override
123151
public void testFloat(float v) throws Exception {
124152
MessagePack msgpack = new MessagePack();

0 commit comments

Comments
 (0)