Skip to content

Commit 1011274

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
OperationMutator: Mutate string literals instead of just replacing them
There might be some benefit in having "almost valid" base64 or hex strings. Similar arguments could apply for regular expressions etc. On top of that, this CL also allows replacing the characters with non-alphanumerical characters like emojis or emojis with modifiers. Bug: 443906260 Change-Id: I8f705f2318c9bbaa6cd639b93c23bf6fbf16e62b Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8578341 Auto-Submit: Matthias Liedtke <mliedtke@google.com> Reviewed-by: Samuel Groß <saelo@google.com> Commit-Queue: Samuel Groß <saelo@google.com>
1 parent 3b6227b commit 1011274

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

Sources/Fuzzilli/Mutators/OperationMutator.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,41 @@ public class OperationMutator: BaseInstructionMutator {
5050
newOp = LoadBigInt(value: b.randomInt())
5151
case .loadFloat(_):
5252
newOp = LoadFloat(value: b.randomFloat())
53-
case .loadString(_):
54-
newOp = LoadString(value: b.randomString())
53+
case .loadString(let op):
54+
let charSetAlNum = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
55+
// TODO(mliedtke): Should we also use some more esoteric characters in initial string
56+
// creation, e.g. ProgramBuilder.randomString?
57+
let charSetExtended = charSetAlNum + Array("-_.,!?<>()[]{}`´^\\/|+#*=;:'~^²\t°ß¿ 🤯🙌🏿\u{202D}")
58+
let randomIndex = {(s: String) in
59+
s.index(s.startIndex, offsetBy: Int.random(in: 0..<s.count))
60+
}
61+
let randomCharacter = {
62+
// Add an overweight to the alpha-numeric characters.
63+
(Bool.random() ? charSetAlNum : charSetExtended).randomElement()!
64+
}
65+
// With a 50% chance create a new string, otherwise perform a modification on the
66+
// existing string. Modifying the string can be especially interesting for
67+
// decoders for RegEx, base64, hex, ...
68+
let newString = op.value.isEmpty || Bool.random() ? b.randomString() : withEqualProbability(
69+
{
70+
// Replace a single character.
71+
var result = op.value
72+
let index = randomIndex(result)
73+
result.replaceSubrange(index..<result.index(index, offsetBy: 1), with: String(randomCharacter()))
74+
return result
75+
}, {
76+
// Insert a single character.
77+
var result = op.value
78+
result.insert(randomCharacter(), at: randomIndex(result))
79+
return result
80+
}, {
81+
// Remove a single character.
82+
var result = op.value
83+
result.remove(at: randomIndex(result))
84+
return result
85+
}
86+
)
87+
newOp = LoadString(value: newString)
5588
case .loadRegExp(let op):
5689
newOp = withEqualProbability({
5790
let (pattern, flags) = b.randomRegExpPatternAndFlags()

0 commit comments

Comments
 (0)