-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathIonInfrastructureFuzzer.java
More file actions
93 lines (80 loc) · 3.66 KB
/
IonInfrastructureFuzzer.java
File metadata and controls
93 lines (80 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazon.ion.fuzz;
import com.amazon.ion.*;
import com.amazon.ion.facet.Facets;
import com.amazon.ion.system.IonSystemBuilder;
import com.amazon.ion.system.SimpleCatalog;
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class IonInfrastructureFuzzer {
@FuzzTest(maxDuration = "15m")
public void myFuzzTest(FuzzedDataProvider data) {
// Strategy 1: Custom Catalog and SystemBuilder configuration
SimpleCatalog catalog = new SimpleCatalog();
// Populate catalog with some random shared symtabs
int symtabs = data.consumeInt(0, 5);
for (int i = 0; i < symtabs; i++) {
String name = data.consumeString(10);
int version = data.consumeInt(1, 10);
try {
// We need a real shared symtab, but creating one usually requires a system or loader
// For now, let's just use the catalog logic with the system we build
} catch (Exception e) {}
}
IonSystemBuilder builder = IonSystemBuilder.standard()
.withCatalog(catalog)
.withStreamCopyOptimized(data.consumeBoolean());
IonSystem ionSys = builder.build();
byte[] input = data.consumeBytes(data.consumeInt(0, 2000));
if (input.length == 0) return;
try {
// Strategy 2: Test SeekableReader and Spans via Facets
try (IonReader reader = ionSys.newReader(input)) {
SeekableReader seekable = Facets.asFacet(SeekableReader.class, reader);
if (seekable != null) {
while (reader.next() != null) {
try {
Span span = Facets.asFacet(Span.class, reader);
if (span != null && data.consumeBoolean()) {
seekable.hoist(span);
}
} catch (Exception e) {}
}
}
}
} catch (Exception e) {}
try {
// Strategy 3: Compare Lite vs Standard System for same input
IonSystem liteSys = IonSystemBuilder.standard().build(); // Lite is default in standard builder
IonDatagram dg1 = ionSys.getLoader().load(input);
IonDatagram dg2 = liteSys.getLoader().load(input);
// Exercise equivalence and hashcode across systems
dg1.equals(dg2);
dg1.hashCode();
} catch (Exception e) {}
try {
// Strategy 4: IonWriter with different configurations
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (IonWriter writer = ionSys.newBinaryWriter(baos)) {
// Perform some writes that might trigger experimental optimizations
IonReader reader = ionSys.newReader(input);
writer.writeValues(reader);
}
} catch (Exception e) {}
}
}