Skip to content

Commit 01fe76a

Browse files
committed
Fix #257
1 parent f798ced commit 01fe76a

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

release-notes/CREDITS-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ Fabian Meumertzheim (fmeum@github)
165165

166166
* Reported #236: `ArrayIndexOutOfBoundsException` in `CBORParser` for invalid UTF-8 String
167167
(2.12.2)
168+
* Reported #257: (smile) Uncaught validation problem wrt Smile "BigDecimal" type
169+
(2.12.3)
168170

169171
(jhhladky@github)
170172

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Modules:
1010
=== Releases ===
1111
------------------------------------------------------------------------
1212

13+
2.12.3 (not yet released)
14+
15+
#257: (smile) Uncaught validation problem wrt Smile "BigDecimal" type
16+
(reported by Fabian M)
17+
1318
2.12.2 (03-Mar-2021)
1419

1520
#236: (cbor) `ArrayIndexOutOfBoundsException` in `CBORParser` for invalid UTF-8 String

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java

+8
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,10 @@ private final int _fourBytesToIntSlow() throws IOException
20992099
private final void _finishBigInteger() throws IOException
21002100
{
21012101
byte[] raw = _read7BitBinaryWithLength();
2102+
if (raw.length == 0) {
2103+
// [dataformats-binary#257]: illegal to have 0-length contents
2104+
_reportError("Invalid encoding of `BigInteger`: length 0");
2105+
}
21022106
_numberBigInt = new BigInteger(raw);
21032107
_numTypesValid = NR_BIGINT;
21042108
_numberType = NumberType.BIG_INTEGER;
@@ -2141,6 +2145,10 @@ private final void _finishBigDecimal() throws IOException
21412145
{
21422146
int scale = SmileUtil.zigzagDecode(_readUnsignedVInt());
21432147
byte[] raw = _read7BitBinaryWithLength();
2148+
if (raw.length == 0) {
2149+
// [dataformats-binary#257]: illegal to have 0-length contents
2150+
_reportError("Invalid encoding of `BigDecimal` value: length 0");
2151+
}
21442152
_numberBigDecimal = new BigDecimal(new BigInteger(raw), scale);
21452153
_numTypesValid = NR_BIGDECIMAL;
21462154
_numberType = NumberType.BIG_DECIMAL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fasterxml.jackson.dataformat.smile.fuzz;
2+
3+
import com.fasterxml.jackson.core.exc.StreamReadException;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
7+
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
8+
9+
public class Fuzz3168BigDecimalTest extends BaseTestForSmile
10+
{
11+
private final ObjectMapper MAPPER = smileMapper();
12+
13+
// Payload:
14+
public void testInvalidBigDecimal() throws Exception
15+
{
16+
final byte[] input = new byte[] {
17+
0x3A, 0x29, 0x0A, 0x00, // smile signature
18+
0x2A, // BigDecimal
19+
(byte) 0xBF, // scale: -32
20+
(byte) 0x80 // length: 0 (invalid
21+
};
22+
try {
23+
/*JsonNode root =*/ MAPPER.readTree(input);
24+
fail("Should not pass");
25+
} catch (StreamReadException e) {
26+
verifyException(e, "Invalid encoding of `BigDecimal` value: length 0");
27+
}
28+
}
29+
}

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/mapper/BiggerDataParseTest.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.*;
55

66
import com.fasterxml.jackson.databind.*;
7+
import com.fasterxml.jackson.databind.json.JsonMapper;
78
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
89

910
/**
@@ -79,12 +80,12 @@ static class Area {
7980
/**********************************************************
8081
*/
8182

82-
final ObjectMapper JSON_MAPPER = new ObjectMapper();
83-
84-
public void testReading() throws Exception
85-
{
86-
Citm citm0 = JSON_MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"),
87-
Citm.class);
83+
private final ObjectMapper JSON_MAPPER = new JsonMapper();
84+
85+
public void testReading() throws Exception
86+
{
87+
Citm citm0 = JSON_MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"),
88+
Citm.class);
8889

8990
ObjectMapper smiler = smileMapper(false);
9091
byte[] smile = smiler.writeValueAsBytes(citm0);

0 commit comments

Comments
 (0)