File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
main/java/com/fasterxml/jackson/dataformat/cbor
test/java/com/fasterxml/jackson/dataformat/cbor/fuzz Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -2415,6 +2415,7 @@ private final int _nextByte() throws IOException {
2415
2415
return _inputBuffer [_inputPtr ++];
2416
2416
}
2417
2417
2418
+ // NOTE! ALWAYS called for non-first byte of multi-byte UTF-8 code point
2418
2419
private final int _nextChunkedByte () throws IOException {
2419
2420
int inPtr = _inputPtr ;
2420
2421
@@ -2427,6 +2428,7 @@ private final int _nextChunkedByte() throws IOException {
2427
2428
return ch ;
2428
2429
}
2429
2430
2431
+ // NOTE! ALWAYS called for non-first byte of multi-byte UTF-8 code point
2430
2432
private final int _nextChunkedByte2 () throws IOException
2431
2433
{
2432
2434
// two possibilities: either end of buffer (in which case, just load more),
@@ -2449,10 +2451,18 @@ private final int _nextChunkedByte2() throws IOException
2449
2451
}
2450
2452
int len = _decodeChunkLength (CBORConstants .MAJOR_TYPE_TEXT );
2451
2453
// not actually acceptable if we got a split character
2452
- if (len < 0 ) {
2454
+ // 29-Jun-2021, tatu: As per CBOR spec:
2455
+ // "Note that this implies that the bytes of a single UTF-8 character cannot be
2456
+ // spread between chunks: a new chunk can only be started at a character boundary."
2457
+ // -> 0-length chunk not allowed either
2458
+ if (len <= 0 ) {
2453
2459
_reportInvalidEOF (": chunked Text ends with partial UTF-8 character" ,
2454
2460
JsonToken .VALUE_STRING );
2455
2461
}
2462
+ if (_inputPtr >= _inputEnd ) { // Must have at least one byte to return
2463
+ loadMoreGuaranteed ();
2464
+ }
2465
+
2456
2466
int end = _inputPtr + len ;
2457
2467
if (end <= _inputEnd ) { // all within buffer
2458
2468
_chunkLeft = 0 ;
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .dataformat .cbor .fuzz ;
2
+
3
+ import com .fasterxml .jackson .core .JsonParser ;
4
+ import com .fasterxml .jackson .core .JsonToken ;
5
+ import com .fasterxml .jackson .core .io .JsonEOFException ;
6
+
7
+ import com .fasterxml .jackson .databind .ObjectMapper ;
8
+
9
+ import com .fasterxml .jackson .dataformat .cbor .CBORTestBase ;
10
+
11
+ public class Fuzz32912ChunkedTextTest extends CBORTestBase
12
+ {
13
+ private final ObjectMapper MAPPER = cborMapper ();
14
+
15
+ public void testInvalidShortText () throws Exception
16
+ {
17
+ final byte [] input = new byte [] {
18
+ 0x7F , 0x61 ,
19
+ (byte ) 0xF3 , 0x61
20
+ };
21
+
22
+ try (JsonParser p = MAPPER .createParser (input )) {
23
+ // Won't fail immediately
24
+ assertToken (JsonToken .VALUE_STRING , p .nextToken ());
25
+ try {
26
+ String str = p .getText ();
27
+ fail ("Should not get String value but exception, got: [" +str +"]" );
28
+ } catch (JsonEOFException e ) {
29
+ verifyException (e , "Unexpected end-of-input in VALUE_STRING" );
30
+ }
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ Modules:
10
10
== = Releases == =
11
11
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
12
12
13
+ 2.12 .4 (not yet released )
14
+
15
+ #287 : (cbor ) Uncaught exception in CBORParser ._nextChunkedByte2 (by ossfuzzer )
16
+
13
17
2.12 .3 (12 - Apr - 2021 )
14
18
15
19
#257 : (smile ) Uncaught validation problem wrt Smile "BigDecimal" type
You can’t perform that action at this time.
0 commit comments