Skip to content

Commit aeac2f1

Browse files
committed
Fixed #258
1 parent 01fe76a commit aeac2f1

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

Diff for: release-notes/CREDITS-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Fabian Meumertzheim (fmeum@github)
167167
(2.12.2)
168168
* Reported #257: (smile) Uncaught validation problem wrt Smile "BigDecimal" type
169169
(2.12.3)
170+
* Reported #258: (smile) ArrayIndexOutOfBoundsException for malformed Smile header
171+
(2.12.3)
170172

171173
(jhhladky@github)
172174

Diff for: release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Modules:
1414

1515
#257: (smile) Uncaught validation problem wrt Smile "BigDecimal" type
1616
(reported by Fabian M)
17+
#258: (smile) ArrayIndexOutOfBoundsException for malformed Smile header
18+
(reported by Fabian M)
1719

1820
2.12.2 (03-Mar-2021)
1921

Diff for: smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,19 @@ protected boolean handleSignature(boolean consumeFirstByte, boolean throwExcepti
157157
if (consumeFirstByte) {
158158
++_inputPtr;
159159
}
160-
if (_nextByteGuaranteed() != SmileConstants.HEADER_BYTE_2) {
160+
byte b = _nextByteGuaranteed();
161+
if (b != SmileConstants.HEADER_BYTE_2) {
161162
if (throwException) {
162163
_reportError("Malformed content: signature not valid, starts with 0x3a but followed by 0x"
163-
+Integer.toHexString(_inputBuffer[_inputPtr])+", not 0x29");
164+
+Integer.toHexString(b & 0xFF)+", not 0x29");
164165
}
165166
return false;
166167
}
167-
if (_nextByteGuaranteed() != SmileConstants.HEADER_BYTE_3) {
168+
b = _nextByteGuaranteed();
169+
if (b != SmileConstants.HEADER_BYTE_3) {
168170
if (throwException) {
169171
_reportError("Malformed content: signature not valid, starts with 0x3a, 0x29, but followed by 0x"
170-
+Integer.toHexString(_inputBuffer[_inputPtr])+", not 0xA");
172+
+Integer.toHexString(b & 0xFF)+", not 0xA");
171173
}
172174
return false;
173175
}

Diff for: smile/src/test/java/com/fasterxml/jackson/dataformat/smile/fuzz/Fuzz3168BigDecimalTest.java renamed to smile/src/test/java/com/fasterxml/jackson/dataformat/smile/fuzz/Fuzz32168BigDecimalTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

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

9-
public class Fuzz3168BigDecimalTest extends BaseTestForSmile
9+
// For [dataformats-binary#257]
10+
public class Fuzz32168BigDecimalTest extends BaseTestForSmile
1011
{
1112
private final ObjectMapper MAPPER = smileMapper();
1213

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fasterxml.jackson.dataformat.smile.fuzz;
2+
3+
import com.fasterxml.jackson.core.exc.StreamReadException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
6+
7+
//For [dataformats-binary#258]
8+
public class Fuzz32169HeaderDecodeTest extends BaseTestForSmile
9+
{
10+
private final ObjectMapper MAPPER = smileMapper();
11+
12+
// Payload:
13+
public void testInvalidHeader() throws Exception
14+
{
15+
final byte[] input = new byte[] {
16+
0x3A, 0x20 // (broken) smile signature
17+
};
18+
try {
19+
/*JsonNode root =*/ MAPPER.readTree(input);
20+
fail("Should not pass");
21+
} catch (StreamReadException e) {
22+
verifyException(e, "Malformed content: signature not valid, starts with 0x3a but");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)