Skip to content

Commit 231fcbc

Browse files
committed
fix: properly instrument nested records
When passing ClassReader to ClassWriter, ASM can copy constant pool entries directly from the original bytecode. Attributes that reference the constant pool remain valid. Prior to this fix, a segfault was triggered for nested records that use Jazzer annotations when Jazzer was trying to access data on record components, when trying to create a record mutator.
1 parent f8668e2 commit 231fcbc

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/main/java/com/code_intelligence/jazzer/instrumentor/TraceDataFlowInstrumentor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal class TraceDataFlowInstrumentor(
5252
}
5353
}
5454

55-
val writer = ClassWriter(ClassWriter.COMPUTE_MAXS)
55+
val writer = ClassWriter(reader, ClassWriter.COMPUTE_MAXS)
5656
node.accept(writer)
5757
return writer.toByteArray()
5858
}

tests/BUILD.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,37 @@ java_fuzz_target_test(
10771077
],
10781078
)
10791079

1080+
java_fuzz_target_test(
1081+
name = "NestedRecordFuzzer",
1082+
timeout = "short",
1083+
srcs = [
1084+
"src/test/java/com/example/NestedRecordFuzzer.java",
1085+
],
1086+
# This regression test checks if we instrument fuzz test classes with nested records correctly,
1087+
# and can start a fuzzing run at all without getting segfaults.
1088+
fuzzer_args = [
1089+
"-print_final_stats=1",
1090+
"-runs=1",
1091+
],
1092+
javacopts = [
1093+
"--release",
1094+
"17",
1095+
],
1096+
tags = [
1097+
"no-jdk8",
1098+
],
1099+
target_class = "com.example.NestedRecordFuzzer",
1100+
runtime_deps = [
1101+
"@maven//:org_junit_jupiter_junit_jupiter_engine",
1102+
],
1103+
deps = [
1104+
"//deploy:jazzer-junit",
1105+
"//deploy:jazzer-project",
1106+
"@maven//:org_junit_jupiter_junit_jupiter_api",
1107+
"@maven//:org_junit_jupiter_junit_jupiter_params",
1108+
],
1109+
)
1110+
10801111
java_fuzz_target_test(
10811112
name = "BigDecimalFuzzer",
10821113
srcs = [
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 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+
import com.code_intelligence.jazzer.junit.FuzzTest;
20+
import com.code_intelligence.jazzer.mutation.annotation.NotNull;
21+
22+
public class NestedRecordFuzzer {
23+
record Address(@NotNull String street, String city, String zipCode) {}
24+
25+
@FuzzTest
26+
public void test(Address ignored) {}
27+
}

0 commit comments

Comments
 (0)