File tree 2 files changed +69
-0
lines changed
cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor
2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -278,4 +278,25 @@ protected static byte[] concat(byte[] ... chunks)
278
278
}
279
279
return bout .toByteArray ();
280
280
}
281
+
282
+ protected byte [] readResource (String ref )
283
+ {
284
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
285
+ final byte [] buf = new byte [4000 ];
286
+
287
+ try (InputStream in = getClass ().getResourceAsStream (ref )) {
288
+ if (in != null ) {
289
+ int len ;
290
+ while ((len = in .read (buf )) > 0 ) {
291
+ bytes .write (buf , 0 , len );
292
+ }
293
+ }
294
+ } catch (IOException e ) {
295
+ throw new RuntimeException ("Failed to read resource '" +ref +"': " +e );
296
+ }
297
+ if (bytes .size () == 0 ) {
298
+ throw new IllegalArgumentException ("Failed to read resource '" +ref +"': empty resource?" );
299
+ }
300
+ return bytes .toByteArray ();
301
+ }
281
302
}
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .dataformat .cbor .failing ;
2
+
3
+ import java .math .BigInteger ;
4
+
5
+ import com .fasterxml .jackson .databind .JsonNode ;
6
+ import com .fasterxml .jackson .databind .ObjectMapper ;
7
+ import com .fasterxml .jackson .dataformat .cbor .CBORTestBase ;
8
+
9
+ public class Fuzz32579BigDecimalTest extends CBORTestBase
10
+ {
11
+ private final ObjectMapper MAPPER = cborMapper ();
12
+
13
+ // [dataformats-binary#267]
14
+ public void testBigDecimalOverflow () throws Exception
15
+ {
16
+ // final byte[] input = readResource("/data/clusterfuzz-cbor-32579.cbor");
17
+ // for (int i = 0; i < input.length; ++i) {
18
+ // System.out.printf("%02X: %02X\n", i, input[i] & 0xFF);
19
+ // }
20
+
21
+ final byte [] input = new byte [] {
22
+ (byte ) 0xC4 , // Tag: decimal fraction
23
+ (byte ) 0x82 ,
24
+ 0x1B ,
25
+ 0x00 , 0x00 , 0x00 , 0x00 ,
26
+ 0x7F ,
27
+ (byte ) 0xFF ,
28
+ (byte ) 0xFF ,
29
+ (byte ) 0xFF ,
30
+ 0x1B ,
31
+ (byte ) 0xC4 ,
32
+ (byte ) 0x82 ,
33
+ 0x1B ,
34
+ 0x2C ,
35
+ 0x25 ,
36
+ (byte ) 0xFF ,
37
+ (byte ) 0xF6 ,
38
+ 0x28 ,
39
+
40
+ };
41
+
42
+
43
+ JsonNode root = MAPPER .readTree (input );
44
+ assertTrue (root .isNumber ());
45
+ assertTrue (root .isBigInteger ());
46
+ assertEquals (BigInteger .ZERO , root .bigIntegerValue ());
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments