Skip to content

Commit f20cf23

Browse files
committed
Fixed #259
1 parent 467b8ce commit f20cf23

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ public JsonToken nextToken() throws IOException
634634
} else {
635635
_tagValue = -1;
636636
}
637-
638637
switch (type) {
639638
case 0: // positive int
640639
_numTypesValid = NR_INT;
@@ -2159,7 +2158,13 @@ protected String _finishTextToken(int ch) throws IOException
21592158
// 29-Jan-2021, tatu: as per [dataformats-binary#238] must keep in mind that
21602159
// the longest individual unit is 4 bytes (surrogate pair) so we
21612160
// actually need len+3 bytes to avoid bounds checks
2162-
final int needed = len + 3;
2161+
2162+
// 19-Mar-2021, tatu: [dataformats-binary#259] shows the case where length
2163+
// we get is Integer.MAX_VALUE, leading to overflow. Could change values
2164+
// to longs but simpler to truncate "needed" (will never pass following test
2165+
// due to inputBuffer never being even close to that big)
2166+
2167+
final int needed = Math.max(len + 3, Integer.MAX_VALUE);
21632168
final int available = _inputEnd - _inputPtr;
21642169

21652170
if ((available >= needed)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fasterxml.jackson.dataformat.cbor.fuzz;
2+
3+
import com.fasterxml.jackson.core.io.JsonEOFException;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
7+
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
8+
9+
public class Fuzz32173ShortTextTest extends CBORTestBase
10+
{
11+
private final ObjectMapper MAPPER = cborMapper();
12+
13+
public void testInvalidShortText() throws Exception
14+
{
15+
final byte[] input = new byte[] {
16+
0x7A, // Text value
17+
0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF // length: Integer.MAX_VALUE
18+
};
19+
try {
20+
/*JsonNode root =*/ MAPPER.readTree(input);
21+
fail("Should not pass, invalid content");
22+
} catch (JsonEOFException e) {
23+
verifyException(e, "Unexpected end-of-input in VALUE_STRING");
24+
}
25+
}
26+
27+
}

release-notes/CREDITS-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ Fabian Meumertzheim (fmeum@github)
169169
(2.12.3)
170170
* Reported #258: (smile) ArrayIndexOutOfBoundsException for malformed Smile header
171171
(2.12.3)
172+
* Reported #259: (cbor) Failed to handle case of alleged String with length of
173+
Integer.MAX_VALUE
174+
(2.12.3)
172175

173176
(jhhladky@github)
174177

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Modules:
1616
(reported by Fabian M)
1717
#258: (smile) ArrayIndexOutOfBoundsException for malformed Smile header
1818
(reported by Fabian M)
19+
#259: (cbor) Failed to handle case of alleged String with length of Integer.MAX_VALUE
20+
(reported by Fabian M)
1921

2022
2.12.2 (03-Mar-2021)
2123

0 commit comments

Comments
 (0)