Skip to content

Commit 9e2e2a3

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[v8] Add ProgramTemplate for --proto-assign-seq-opt pattern
Bug: 429332174 Change-Id: Ic644ce211f96e1bd2c3044bc14fa12ee4410fa24 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8783696 Commit-Queue: Matthias Liedtke <[email protected]> Reviewed-by: Dominik Klemba <[email protected]>
1 parent ec80efa commit 9e2e2a3

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

Sources/FuzzilliCli/Profiles/V8CommonProfile.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,52 @@ public let FastApiCallFuzzer = ProgramTemplate("FastApiCallFuzzer") { b in
686686
b.build(n: 10)
687687
}
688688

689+
public let ProtoAssignSeqOptFuzzer = ProgramTemplate("ProtoAssignSeqOptFuzzer") { b in
690+
b.buildPrefix()
691+
692+
let containingFct = b.buildPlainFunction(with: b.randomParameters()) { args in
693+
// The function to install the prototypes on.
694+
let params = b.randomParameters()
695+
let body = {(args: [Variable]) in
696+
b.build(n: 20)
697+
b.doReturn(b.randomVariable(forUseAs: .object()))
698+
}
699+
let fct = withEqualProbability(
700+
{b.buildPlainFunction(with: params, body)},
701+
{b.buildArrowFunction(with: params, body)},
702+
{b.buildGeneratorFunction(with: params, body)}, // not a valid constructor
703+
{b.buildAsyncFunction(with: params, body)}, // not a valid constructor
704+
{b.buildConstructor(with: params, body)},
705+
{b.buildClassDefinition(withSuperclass: b.randomVariable(forUseAs: .object())) { _ in
706+
b.build(n: 30)
707+
}}
708+
)
709+
// Explicitly expose the prototype property to make modifications of it more likely.
710+
b.getProperty("prototype", of: fct)
711+
// Allow further modifications on the function.
712+
b.build(n: 10)
713+
// Perform the prototype assignments.
714+
for _ in 0..<Int.random(in: 2...10) {
715+
let val = b.randomVariable(forUseAs: .primitive)
716+
let name = b.randomCustomPropertyName()
717+
// TODO(mliedtke): This should be a setProperty(getProperty("prototype")) instead of
718+
// treating `prototype.name` as a single property.
719+
b.setProperty("prototype.\(name)", of: fct, to: val)
720+
}
721+
// Allow further modifications after the optimized sequence.
722+
b.build(n: 10)
723+
// Construct the object with the `new` keyword. Add a guard because not all chosen functions
724+
// are valid constructors.
725+
b.construct(fct, withArgs: b.randomArguments(forCalling: fct), guard: true)
726+
// Generate arbitrary code that could also use the constructed object.
727+
b.build(n: 30)
728+
b.doReturn(b.randomJsVariable())
729+
}
730+
let sig = b.type(of: containingFct).signature ?? Signature.forUnknownFunction
731+
b.callFunction(containingFct, withArgs: b.randomArguments(forCalling: containingFct))
732+
b.build(n: 10)
733+
}
734+
689735
// Configure V8 invocation arguments. `forSandbox` is used by the V8SandboxProfile. As the sandbox
690736
// fuzzer does not crash on regular assertions, most validation flags do not make sense in that
691737
// configuraiton.

Sources/FuzzilliCli/Profiles/V8Profile.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,25 @@ let v8Profile = Profile(
7272
],
7373

7474
additionalProgramTemplates: WeightedList<ProgramTemplate>([
75-
(MapTransitionFuzzer, 1),
76-
(ValueSerializerFuzzer, 1),
77-
(V8RegExpFuzzer, 1),
78-
(WasmFastCallFuzzer, 1),
79-
(FastApiCallFuzzer, 1),
80-
(LazyDeoptFuzzer, 1),
81-
(WasmDeoptFuzzer, 1),
82-
(WasmTurbofanFuzzer, 1),
75+
(MapTransitionFuzzer, 1),
76+
(ValueSerializerFuzzer, 1),
77+
(V8RegExpFuzzer, 1),
78+
(WasmFastCallFuzzer, 1),
79+
(FastApiCallFuzzer, 1),
80+
(LazyDeoptFuzzer, 1),
81+
(WasmDeoptFuzzer, 1),
82+
(WasmTurbofanFuzzer, 1),
83+
(ProtoAssignSeqOptFuzzer, 1),
8384
]),
8485

8586
disabledCodeGenerators: [],
8687

8788
disabledMutators: [],
8889

8990
additionalBuiltins: [
90-
"gc" : .function([.opt(gcOptions.instanceType)] => (.undefined | .jsPromise)),
91-
"d8" : .jsD8,
92-
"Worker" : .constructor([.jsAnything, .object()] => .object(withMethods: ["postMessage","getMessage"])),
91+
"gc" : .function([.opt(gcOptions.instanceType)] => (.undefined | .jsPromise)),
92+
"d8" : .jsD8,
93+
"Worker": .constructor([.jsAnything, .object()] => .object(withMethods: ["postMessage","getMessage"])),
9394
],
9495

9596
additionalObjectGroups: [jsD8, jsD8Test, jsD8FastCAPI, gcOptions],

0 commit comments

Comments
 (0)