• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 import com.code_intelligence.jazzer.api.FuzzedDataProvider;
18 
19 import com.esotericsoftware.kryo.Kryo;
20 import com.esotericsoftware.kryo.io.Input;
21 import com.esotericsoftware.kryo.KryoException;
22 import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer;
23 
24 import java.util.*;
25 import java.util.concurrent.atomic.AtomicInteger;
26 import java.util.concurrent.atomic.AtomicLong;
27 import java.math.BigDecimal;
28 import java.math.BigInteger;
29 
30 public class DeserializeNumbersFuzzer {
fuzzerTestOneInput(FuzzedDataProvider data)31     public static void fuzzerTestOneInput(FuzzedDataProvider data) {
32         Kryo kryo = new Kryo();
33         kryo.register(SomeClass.class);
34 
35         kryo.setReferences(data.consumeBoolean());
36         if (data.consumeBoolean())
37             kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
38 
39         Input in = new Input(data.consumeRemainingAsBytes());
40         try {
41             kryo.readObject(in, SomeClass.class);
42         } catch (KryoException e) {
43         } finally {
44             in.close();
45         }
46     }
47 
48     public static final class SomeClass {
49         Date _date;
50         TimeZone _timeZone;
51         Calendar _calendar;
52         Locale _locale;
53         Integer[] _integerArray;
54         boolean _boolean;
55         char _char;
56         byte _byte;
57         short _short;
58         int _int1;
59         int _int2;
60         long _long;
61         float _float;
62         double _double;
63         Boolean _Boolean;
64         Character _Character;
65         Byte _Byte;
66         Short _Short;
67         Integer _Integer;
68         Long _Long;
69         Float _Float;
70         Double _Double;
71         BigInteger _bigInteger;
72         BigDecimal _bigDecimal;
73         AtomicInteger _atomicInteger;
74         AtomicLong _atomicLong;
75     }
76 }
77