Skip to content

Commit

Permalink
Fix #257
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 19, 2021
1 parent f798ced commit 01fe76a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
2 changes: 2 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ Fabian Meumertzheim (fmeum@github)

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

(jhhladky@github)

Expand Down
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Modules:
=== Releases ===
------------------------------------------------------------------------

2.12.3 (not yet released)

#257: (smile) Uncaught validation problem wrt Smile "BigDecimal" type
(reported by Fabian M)

2.12.2 (03-Mar-2021)

#236: (cbor) `ArrayIndexOutOfBoundsException` in `CBORParser` for invalid UTF-8 String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,10 @@ private final int _fourBytesToIntSlow() throws IOException
private final void _finishBigInteger() throws IOException
{
byte[] raw = _read7BitBinaryWithLength();
if (raw.length == 0) {
// [dataformats-binary#257]: illegal to have 0-length contents
_reportError("Invalid encoding of `BigInteger`: length 0");
}
_numberBigInt = new BigInteger(raw);
_numTypesValid = NR_BIGINT;
_numberType = NumberType.BIG_INTEGER;
Expand Down Expand Up @@ -2141,6 +2145,10 @@ private final void _finishBigDecimal() throws IOException
{
int scale = SmileUtil.zigzagDecode(_readUnsignedVInt());
byte[] raw = _read7BitBinaryWithLength();
if (raw.length == 0) {
// [dataformats-binary#257]: illegal to have 0-length contents
_reportError("Invalid encoding of `BigDecimal` value: length 0");
}
_numberBigDecimal = new BigDecimal(new BigInteger(raw), scale);
_numTypesValid = NR_BIGDECIMAL;
_numberType = NumberType.BIG_DECIMAL;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.fasterxml.jackson.dataformat.smile.fuzz;

import com.fasterxml.jackson.core.exc.StreamReadException;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;

public class Fuzz3168BigDecimalTest extends BaseTestForSmile
{
private final ObjectMapper MAPPER = smileMapper();

// Payload:
public void testInvalidBigDecimal() throws Exception
{
final byte[] input = new byte[] {
0x3A, 0x29, 0x0A, 0x00, // smile signature
0x2A, // BigDecimal
(byte) 0xBF, // scale: -32
(byte) 0x80 // length: 0 (invalid
};
try {
/*JsonNode root =*/ MAPPER.readTree(input);
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Invalid encoding of `BigDecimal` value: length 0");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;

/**
Expand Down Expand Up @@ -79,12 +80,12 @@ static class Area {
/**********************************************************
*/

final ObjectMapper JSON_MAPPER = new ObjectMapper();
public void testReading() throws Exception
{
Citm citm0 = JSON_MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"),
Citm.class);
private final ObjectMapper JSON_MAPPER = new JsonMapper();

public void testReading() throws Exception
{
Citm citm0 = JSON_MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"),
Citm.class);

ObjectMapper smiler = smileMapper(false);
byte[] smile = smiler.writeValueAsBytes(citm0);
Expand Down

0 comments on commit 01fe76a

Please sign in to comment.