Skip to content

Commit 2bd387d

Browse files
authored
support generation of array with holes (googleprojectzero#197)
1 parent 9018842 commit 2bd387d

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Sources/Fuzzilli/Lifting/JavaScriptLifter.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ public class JavaScriptLifter: Lifter {
187187
output = ObjectLiteral.new("{" + properties.joined(separator: ",") + "}")
188188

189189
case is CreateArray:
190-
let elems = instr.inputs.map({ expr(for: $0).text }).joined(separator: ",")
190+
// When creating arrays, treat undefined elements as holes. This also relies on literals always being inlined.
191+
let elems = instr.inputs.map({ let text = expr(for: $0).text; return text == "undefined" ? "" : text }).joined(separator: ",")
191192
output = ArrayLiteral.new("[" + elems + "]")
192193

193194
case let op as CreateObjectWithSpread:

Tests/FuzzilliTests/LifterTest.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,36 @@ class LifterTests: XCTestCase {
363363

364364
XCTAssertEqual(lifted_program,expected_program)
365365
}
366+
367+
func testHoleyArrayLifting(){
368+
let fuzzer = makeMockFuzzer()
369+
let b = fuzzer.makeBuilder()
370+
371+
var initialValues = [Variable]()
372+
initialValues.append(b.loadInt(1))
373+
initialValues.append(b.loadInt(2))
374+
initialValues.append(b.loadUndefined())
375+
initialValues.append(b.loadInt(4))
376+
initialValues.append(b.loadUndefined())
377+
initialValues.append(b.loadInt(6))
378+
let v = b.loadString("foobar")
379+
b.reassign(v, to: b.loadUndefined())
380+
initialValues.append(v)
381+
b.createArray(with: initialValues)
382+
383+
let program = b.finalize()
384+
385+
let lifted_program = fuzzer.lifter.lift(program)
386+
387+
let expected_program = """
388+
let v6 = "foobar";
389+
v6 = undefined;
390+
const v8 = [1,2,,4,,6,v6];
391+
392+
"""
393+
394+
XCTAssertEqual(lifted_program,expected_program)
395+
}
366396
}
367397

368398
extension LifterTests {
@@ -376,6 +406,7 @@ extension LifterTests {
376406
("testDoWhileLifting", testDoWhileLifting),
377407
("testBlockStatements", testBlockStatements),
378408
("testAsyncGeneratorLifting", testAsyncGeneratorLifting),
409+
("testHoleyArray", testHoleyArrayLifting),
379410
]
380411
}
381412
}

Tests/FuzzilliTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extension LifterTests {
5959
("testFuzzILLifter", testFuzzILLifter),
6060
("testLiftingOptions", testLiftingOptions),
6161
("testNestedCodeStrings", testNestedCodeStrings),
62+
("testHoleyArray", testHoleyArrayLifting),
6263
]
6364
}
6465

0 commit comments

Comments
 (0)