1
1
package com .fasterxml .jackson .dataformat .cbor ;
2
2
3
- import com .fasterxml .jackson .databind .JsonNode ;
4
- import com .fasterxml .jackson .databind .ObjectMapper ;
5
- import org .junit .Test ;
6
-
7
3
import java .io .ByteArrayInputStream ;
8
4
import java .io .IOException ;
5
+ import java .io .InputStream ;
9
6
import java .io .SequenceInputStream ;
10
7
11
- // for [dataformat-cbor#13]
8
+ import com .fasterxml .jackson .core .JsonFactory ;
9
+ import com .fasterxml .jackson .core .JsonParser ;
10
+
11
+ import com .fasterxml .jackson .databind .JsonNode ;
12
+ import com .fasterxml .jackson .databind .ObjectMapper ;
13
+
12
14
public class ParserInputStreamTest extends CBORTestBase
13
15
{
14
- @ Test
16
+ private final ObjectMapper MAPPER = cborMapper ();
17
+
18
+ // for [dataformat-cbor#13]
15
19
public void testInpuStream () throws Exception {
16
- CBORFactory f = new CBORFactory ();
17
- ObjectMapper cborMapper = new ObjectMapper (new CBORFactory ());
18
- byte [] buffer = generateHugeCBOR (f );
20
+ byte [] buffer = generateHugeCBOR (MAPPER .getFactory ());
19
21
20
22
// split the buffer in two smaller buffer
21
23
int len = 160 ;
@@ -29,11 +31,34 @@ public void testInpuStream() throws Exception {
29
31
ByteArrayInputStream in2 = new ByteArrayInputStream (buf2 );
30
32
SequenceInputStream inputStream = new SequenceInputStream (in1 , in2 );
31
33
32
- JsonNode jsonNode = cborMapper .readTree (inputStream );
34
+ JsonNode jsonNode = MAPPER .readTree (inputStream );
33
35
assertNotNull (jsonNode );
34
36
}
35
37
36
- private byte [] generateHugeCBOR (CBORFactory f ) throws IOException {
38
+ public void testInputStreamWithHugeValueThatOverlaps () throws Exception {
39
+ final byte [] buffer = new byte [8002 ];
40
+ buffer [0 ] = 0x79 ; // string length 7996 + 3 init bytes
41
+ buffer [1 ] = 0x1f ;
42
+ buffer [2 ] = 0x3c ;
43
+ buffer [7999 ] = 0x61 ; // string length 1 + 1 init byte
44
+
45
+ final InputStream in = new ByteArrayInputStream (buffer );
46
+ final JsonParser parser = MAPPER .getFactory ().createParser (in );
47
+
48
+ parser .nextToken ();
49
+ parser .finishToken ();
50
+
51
+ final long start = parser .getCurrentLocation ().getByteOffset ();
52
+ assertEquals (7999 , start );
53
+
54
+ parser .nextToken ();
55
+ parser .finishToken ();
56
+
57
+ final long end = parser .getCurrentLocation ().getByteOffset ();
58
+ assertEquals (8001 , end );
59
+ }
60
+
61
+ private byte [] generateHugeCBOR (JsonFactory f ) throws IOException {
37
62
String hugeJson = "{" ;
38
63
for (char c ='a' ; c <= 'z' ; c ++) {
39
64
for (char cc ='a' ; cc <= 'z' ; cc ++) {
0 commit comments