Skip to content

Commit eb8a1ea

Browse files
bertschneiderfmeum
authored andcommitted
agent: Ignore offline instrumentation
JaCoCo is able to offline instrument classes. It determines if classes, which should be instrumented dynamically, are already instrumented by checking the existence of the coverage data field, and throws an exception if it's present. Jazzer's `IProbeArrayStrategy` already does not add the coverage data field. This PR also removes JaCoCo's check if the field is present, and so enables fuzzing of offline instrumented classes.
1 parent 99dc877 commit eb8a1ea

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

repositories.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def jazzer_dependencies():
145145
patches = [
146146
Label("//third_party:jacoco-make-probe-adapter-subclassable.patch"),
147147
Label("//third_party:jacoco-make-probe-inserter-subclassable.patch"),
148+
Label("//third_party:jacoco-ignore-offline-instrumentation.patch"),
148149
],
149150
sha256 = "c603cfcc5f3d95ecda46fb369dc54c82a453bb6b640a605c3970607d10896725",
150151
strip_prefix = "jacoco-0.8.8",

tests/BUILD.bazel

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,38 @@ java_fuzz_target_test(
389389
allowed_findings = ["com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh"],
390390
target_class = "com.example.SilencedFuzzer",
391391
)
392+
393+
java_binary(
394+
name = "jacococli",
395+
main_class = "org.jacoco.cli.internal.Main",
396+
runtime_deps = ["@jacococli//file:jacococli.jar"],
397+
)
398+
399+
java_library(
400+
name = "OfflineInstrumentedTarget",
401+
srcs = ["src/test/java/com/example/OfflineInstrumentedTarget.java"],
402+
)
403+
404+
genrule(
405+
name = "OfflineInstrumentedTargetInstrumented",
406+
srcs = [":OfflineInstrumentedTarget"],
407+
outs = ["OfflineInstrumentedTargetInstrumented.jar"],
408+
cmd = """
409+
$(location :jacococli) instrument $< --dest jacoco-instrumented
410+
cp jacoco-instrumented/*.jar $@
411+
""",
412+
tags = ["manual"],
413+
tools = [":jacococli"],
414+
)
415+
416+
java_fuzz_target_test(
417+
name = "OfflineInstrumentedFuzzer",
418+
timeout = "short",
419+
srcs = ["src/test/java/com/example/OfflineInstrumentedFuzzer.java"],
420+
allowed_findings = ["java.lang.IllegalStateException"],
421+
target_class = "com.example.OfflineInstrumentedFuzzer",
422+
deps = [
423+
":OfflineInstrumentedTargetInstrumented",
424+
"@jacocoagent//file:jacocoagent.jar", # Offline instrumented classes depend on the jacoco agent
425+
],
426+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2023 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example;
18+
19+
public class OfflineInstrumentedFuzzer {
20+
public static void fuzzerTestOneInput(byte[] data) {
21+
OfflineInstrumentedTarget.someFunction(data);
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2023 Code Intelligence GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example;
18+
19+
public class OfflineInstrumentedTarget {
20+
public static void someFunction(byte[] data) {
21+
if (new String(data).equals("found it")) {
22+
throw new IllegalStateException("Expected exception");
23+
}
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
2+
index b8333a2f..1c728638 100644
3+
--- org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
4+
+++ org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java
5+
@@ -234,11 +234,6 @@ public final class InstrSupport {
6+
*/
7+
public static void assertNotInstrumented(final String member,
8+
final String owner) throws IllegalStateException {
9+
- if (member.equals(DATAFIELD_NAME) || member.equals(INITMETHOD_NAME)) {
10+
- throw new IllegalStateException(format(
11+
- "Cannot process instrumented class %s. Please supply original non-instrumented classes.",
12+
- owner));
13+
- }
14+
}
15+
16+
/**

0 commit comments

Comments
 (0)