Skip to content

Commit 7e69549

Browse files
authored
Fixes for #426: Add bound check for array index (#427)
1 parent a0c01db commit 7e69549

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

release-notes/CREDITS-2.x

+5-3
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,11 @@ Simon Daudin (@simondaudin)
284284
Arthur Chan (@arthurscchan)
285285
* Contributed #417: (ion) `IonReader` classes contain assert statement which could throw
286286
unexpected `AssertionError`
287-
(2.17.0)
287+
(2.17.0)
288288
* Contributed #420: (ion) `IndexOutOfBoundsException` thrown by `IonReader` implementations
289-
(2.17.0)
289+
(2.17.0)
290290
* Contributed #424: (ion) `IonReader` throws `NullPointerException` for unchecked
291291
invalid data
292-
(2.17.0)
292+
(2.17.0)
293+
* Contributed #426: (smile) `SmileParser` throws unexpected IOOBE for corrupt content
294+
(2.17.0)

release-notes/VERSION-2.x

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ Active maintainers:
1818

1919
#417: (ion) `IonReader` classes contain assert statement which could throw
2020
unexpected `AssertionError`
21-
(contributed by Arthur C)
21+
(fix contributed by Arthur C)
2222
#420: (ion) `IndexOutOfBoundsException` thrown by `IonReader` implementations
2323
are not handled
24-
(contributed by Arthur C)
24+
(fix contributed by Arthur C)
2525
#424: (ion) `IonReader` throws `NullPointerException` for unchecked invalid data
26-
(contributed by Arthur C)
26+
(fix contributed by Arthur C)
27+
#426: (smile) `SmileParser` throws unexpected IOOBE for corrupt content
28+
(fix contributed by Arthur C)
2729
-(ion) Update `com.amazon.ion:ion-java` to 1.11.0 (from 1.10.5)
2830

2931
2.16.0 (15-Nov-2023)

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

+14
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,11 @@ protected void _skipIncomplete() throws IOException
28932893

28942894
protected void _skipBytes(int len) throws IOException
28952895
{
2896+
// 18-Dec-2023, tatu: Sanity check related to some OSS-Fuzz findings:
2897+
if (len < 0) {
2898+
throw _constructReadException("Internal error: _skipBytes() called with negative value: %d",
2899+
len);
2900+
}
28962901
while (true) {
28972902
int toAdd = Math.min(len, _inputEnd - _inputPtr);
28982903
_inputPtr += toAdd;
@@ -2914,6 +2919,15 @@ protected void _skip7BitBinary() throws IOException
29142919
// Ok; 8 encoded bytes for 7 payload bytes first
29152920
int chunks = origBytes / 7;
29162921
int encBytes = chunks * 8;
2922+
2923+
// sanity check: not all length markers valid; due to signed int(32)
2924+
// calculations maximum length only 7/8 of 2^31
2925+
if (encBytes < 0) {
2926+
throw _constructReadException(
2927+
"Invalid content: invalid 7-bit binary encoded byte length (0x%X) exceeds maximum valid value",
2928+
origBytes);
2929+
}
2930+
29172931
// and for last 0 - 6 bytes, last+1 (except none if no leftovers)
29182932
origBytes -= 7 * chunks;
29192933
if (origBytes > 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fasterxml.jackson.dataformat.smile.fuzz;
2+
3+
import com.fasterxml.jackson.core.*;
4+
import com.fasterxml.jackson.core.exc.StreamReadException;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
7+
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
8+
9+
public class Fuzz_426_65126IOOBETest extends BaseTestForSmile
10+
{
11+
private final ObjectMapper MAPPER = smileMapper();
12+
13+
// [dataformats-binary#426]
14+
public void testInvalidIOOBE() throws Exception
15+
{
16+
final byte[] input = readResource("/data/clusterfuzz-smile-65126.smile");
17+
try (JsonParser p = MAPPER.createParser(input)) {
18+
assertNull(p.nextTextValue());
19+
assertToken(JsonToken.VALUE_EMBEDDED_OBJECT, p.currentToken());
20+
try {
21+
p.nextTextValue();
22+
fail("Should not pass");
23+
} catch (StreamReadException e) {
24+
verifyException(e, "Invalid content: invalid 7-bit binary encoded byte length");
25+
}
26+
}
27+
}
28+
}
Binary file not shown.

0 commit comments

Comments
 (0)