Skip to content

Commit 615b4d6

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
Move base64 code generators from XSProfile to generic list
These were added to the XSProfile in commit fdaaa1f. As V8 now supports base64, we should run these code generators by default. Bug: 443906260 Change-Id: I469f25a9d7044f0a4dc6f303a7f33a18728e65c3 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8578339 Commit-Queue: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Samuel Groß <saelo@google.com>
1 parent 1d94df6 commit 615b4d6

3 files changed

Lines changed: 96 additions & 95 deletions

File tree

Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public let codeGeneratorWeights = [
4747
"LoadNewTargetGenerator": 3,
4848
"DisposableVariableGenerator": 5,
4949
"AsyncDisposableVariableGenerator": 5,
50+
"HexGenerator": 2,
51+
"Base64Generator": 2,
5052

5153
"ObjectLiteralGenerator": 10,
5254
// The following generators determine how frequently different

Sources/Fuzzilli/CodeGen/CodeGenerators.swift

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public let CodeGenerators: [CodeGenerator] = [
143143
b.constructTemporalTime, b.constructTemporalYearMonth, b.constructTemporalMonthDay,
144144
b.constructTemporalDate, b.constructTemporalDateTime, b.constructTemporalZonedDateTime])()
145145
},
146+
146147
ValueGenerator("TypedArrayGenerator") { b, n in
147148
for _ in 0..<n {
148149
let size = b.loadInt(b.randomSize(upTo: 0x1000))
@@ -155,6 +156,99 @@ public let CodeGenerators: [CodeGenerator] = [
155156
}
156157
},
157158

159+
CodeGenerator("HexGenerator") { b in
160+
let hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"]
161+
162+
let Uint8Array = b.createNamedVariable(forBuiltin: "Uint8Array")
163+
164+
withEqualProbability({
165+
var s = ""
166+
for _ in 0..<Int.random(in: 1...10) {
167+
s += chooseUniform(from: hexValues)
168+
s += chooseUniform(from: hexValues)
169+
}
170+
let hex = b.loadString(s)
171+
172+
if probability(0.5) {
173+
b.callMethod("fromHex", on: Uint8Array, withArgs: [hex])
174+
} else {
175+
let target = b.construct(Uint8Array, withArgs: [b.loadInt(Int64.random(in: 0...0x100))])
176+
b.callMethod("setFromHex", on: target, withArgs: [hex])
177+
}
178+
}, {
179+
var values = [Variable]()
180+
for _ in 0..<Int.random(in: 1...20) {
181+
values.append(b.loadInt(Int64.random(in: 0...0xFF)))
182+
}
183+
184+
let bytes = b.callMethod("of", on: Uint8Array, withArgs: values)
185+
b.callMethod("toHex", on: bytes, withArgs: [])
186+
}
187+
)
188+
},
189+
190+
CodeGenerator("Base64Generator") { b in
191+
let base64Alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]
192+
let base64URLAlphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"]
193+
194+
let Uint8Array = b.createNamedVariable(forBuiltin: "Uint8Array")
195+
196+
withEqualProbability({
197+
var options = [String: Variable]()
198+
var alphabet = chooseUniform(from: [base64Alphabet, base64URLAlphabet])
199+
200+
options["alphabet"] = b.loadString((alphabet == base64Alphabet) ? "base64" : "base64url")
201+
options["lastChunkHandling"] = b.loadString(
202+
chooseUniform(
203+
from: ["loose", "strict", "stop-before-partial"]
204+
)
205+
)
206+
207+
var s = ""
208+
for _ in 0..<Int.random(in: 1...32) * 4 {
209+
s += chooseUniform(from: alphabet)
210+
}
211+
212+
// extend by 0, 1, or 2 bytes
213+
switch (Int.random(in: 0...3)) {
214+
case 1:
215+
s += base64Alphabet[Int.random(in: 0...63)]
216+
s += base64Alphabet[Int.random(in: 0...63) & 0x30]
217+
s += "=="
218+
break
219+
220+
case 2:
221+
s += base64Alphabet[Int.random(in: 0...63)]
222+
s += base64Alphabet[Int.random(in: 0...63)]
223+
s += base64Alphabet[Int.random(in: 0...63) & 0x3C]
224+
s += "="
225+
break
226+
227+
default:
228+
break
229+
}
230+
231+
let base64 = b.loadString(s)
232+
233+
let optionsObject = b.createObject(with: options)
234+
if probability(0.5) {
235+
b.callMethod("fromBase64", on: Uint8Array, withArgs: [base64, optionsObject])
236+
} else {
237+
let target = b.construct(Uint8Array, withArgs: [b.loadInt(Int64.random(in: 0...0x100))])
238+
b.callMethod("setFromBase64", on: target, withArgs: [base64, optionsObject])
239+
}
240+
}, {
241+
var values = [Variable]()
242+
for _ in 0..<Int.random(in: 1...64) {
243+
values.append(b.loadInt(Int64.random(in: 0...0xFF)))
244+
}
245+
246+
let bytes = b.callMethod("of", on: Uint8Array, withArgs: values)
247+
b.callMethod("toBase64", on: bytes, withArgs: [])
248+
}
249+
)
250+
},
251+
158252
ValueGenerator("RegExpGenerator") { b, n in
159253
// TODO: this could be a ValueGenerator but currently has a fairly high failure rate.
160254
for _ in 0..<n {

Sources/FuzzilliCli/Profiles/XSProfile.swift

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -129,99 +129,6 @@ fileprivate let UnicodeStringGenerator = CodeGenerator("UnicodeStringGenerator")
129129
b.loadString(s)
130130
}
131131

132-
fileprivate let HexGenerator = CodeGenerator("HexGenerator") { b in
133-
let hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"]
134-
135-
let Uint8Array = b.createNamedVariable(forBuiltin: "Uint8Array")
136-
137-
withEqualProbability({
138-
var s = ""
139-
for _ in 0..<Int.random(in: 1...10) {
140-
s += chooseUniform(from: hexValues)
141-
s += chooseUniform(from: hexValues)
142-
}
143-
let hex = b.loadString(s)
144-
145-
if probability(0.5) {
146-
b.callMethod("fromHex", on: Uint8Array, withArgs: [hex])
147-
} else {
148-
let target = b.construct(Uint8Array, withArgs: [b.loadInt(Int64.random(in: 0...0x100))])
149-
b.callMethod("setFromHex", on: target, withArgs: [hex])
150-
}
151-
}, {
152-
var values = [Variable]()
153-
for _ in 0..<Int.random(in: 1...20) {
154-
values.append(b.loadInt(Int64.random(in: 0...0xFF)))
155-
}
156-
157-
let bytes = b.callMethod("of", on: Uint8Array, withArgs: values)
158-
b.callMethod("toHex", on: bytes, withArgs: [])
159-
}
160-
)
161-
}
162-
163-
fileprivate let Base64Generator = CodeGenerator("Base64Generator") { b in
164-
let base64Alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]
165-
let base64URLAlphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"]
166-
167-
let Uint8Array = b.createNamedVariable(forBuiltin: "Uint8Array")
168-
169-
withEqualProbability({
170-
var options = [String: Variable]()
171-
var alphabet = chooseUniform(from: [base64Alphabet, base64URLAlphabet])
172-
173-
options["alphabet"] = b.loadString((alphabet == base64Alphabet) ? "base64" : "base64url")
174-
options["lastChunkHandling"] = b.loadString(
175-
chooseUniform(
176-
from: ["loose", "strict", "stop-before-partial"]
177-
)
178-
)
179-
180-
var s = ""
181-
for _ in 0..<Int.random(in: 1...32) * 4 {
182-
s += chooseUniform(from: alphabet)
183-
}
184-
185-
// extend by 0, 1, or 2 bytes
186-
switch (Int.random(in: 0...3)) {
187-
case 1:
188-
s += base64Alphabet[Int.random(in: 0...63)]
189-
s += base64Alphabet[Int.random(in: 0...63) & 0x30]
190-
s += "=="
191-
break
192-
193-
case 2:
194-
s += base64Alphabet[Int.random(in: 0...63)]
195-
s += base64Alphabet[Int.random(in: 0...63)]
196-
s += base64Alphabet[Int.random(in: 0...63) & 0x3C]
197-
s += "="
198-
break
199-
200-
default:
201-
break
202-
}
203-
204-
let base64 = b.loadString(s)
205-
206-
let optionsObject = b.createObject(with: options)
207-
if probability(0.5) {
208-
b.callMethod("fromBase64", on: Uint8Array, withArgs: [base64, optionsObject])
209-
} else {
210-
let target = b.construct(Uint8Array, withArgs: [b.loadInt(Int64.random(in: 0...0x100))])
211-
b.callMethod("setFromBase64", on: target, withArgs: [base64, optionsObject])
212-
}
213-
}, {
214-
var values = [Variable]()
215-
for _ in 0..<Int.random(in: 1...64) {
216-
values.append(b.loadInt(Int64.random(in: 0...0xFF)))
217-
}
218-
219-
let bytes = b.callMethod("of", on: Uint8Array, withArgs: values)
220-
b.callMethod("toBase64", on: bytes, withArgs: [])
221-
}
222-
)
223-
}
224-
225132
fileprivate let CompartmentEvaluateGenerator = CodeGenerator("CompartmentEvaluateGenerator", inputs: .required(.object(ofGroup: "Compartment"))) { b, target in
226133
let code = b.buildCodeString() {
227134
b.buildRecursive()
@@ -419,8 +326,6 @@ let xsProfile = Profile(
419326
(CompartmentEvaluateGenerator, 5),
420327
(UnicodeStringGenerator, 2),
421328
(ModuleSourceGenerator, 3),
422-
(HexGenerator, 2),
423-
(Base64Generator, 2),
424329
],
425330

426331
additionalProgramTemplates: WeightedList<ProgramTemplate>([

0 commit comments

Comments
 (0)