Skip to content

Commit

Permalink
Use init(serializedBytes:) instead of init(serializedData:)
Browse files Browse the repository at this point in the history
The latter has been deprecated in favor of the former in SwiftProtobuf.
  • Loading branch information
Samuel Groß committed Jul 30, 2024
1 parent 19e40b8 commit 7cb027f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Sources/FuzzILTool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let filteredFunctionsForCompiler = [
// Loads a serialized FuzzIL program from the given file
func loadProgram(from path: String) throws -> Program {
let data = try Data(contentsOf: URL(fileURLWithPath: path))
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program(from: proto)
return program
}
Expand Down Expand Up @@ -147,7 +147,7 @@ else if args.has("--liftCorpusToJS") {
// This allows the debugging of produced programs that are not syntactically valid
else if args.has("--dumpProtobuf") {
let data = try Data(contentsOf: URL(fileURLWithPath: path))
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
dump(proto, maxDepth: 3)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Compiler/JavaScriptParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class JavaScriptParser {
try runParserScript(withArguments: [astProtobufDefinitionPath, path, outputFilePath])
let data = try Data(contentsOf: URL(fileURLWithPath: outputFilePath))
try FileManager.default.removeItem(atPath: outputFilePath)
return try AST(serializedData: data)
return try AST(serializedBytes: data)
}

private func runParserScript(withArguments arguments: [String]) throws {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Fuzzilli/Modules/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class DistributedFuzzingNode {
/// and importing instances need to be configured identically, see above.
func synchronizeState(to data: Data) throws {
if supportsFastStateSynchronization {
let state = try Fuzzilli_Protobuf_FuzzerState(serializedData: data)
let state = try Fuzzilli_Protobuf_FuzzerState(serializedBytes: data)
try fuzzer.corpus.importState(state.corpus)
try fuzzer.evaluator.importState(state.evaluatorState)
} else {
Expand Down Expand Up @@ -236,7 +236,7 @@ public class DistributedFuzzingParentNode: DistributedFuzzingNode, Module {

case .crashingProgram:
do {
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program(from: proto)
fuzzer.importCrash(program, origin: .child(id: child))
} catch {
Expand All @@ -250,15 +250,15 @@ public class DistributedFuzzingParentNode: DistributedFuzzingNode, Module {
}

do {
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program(from: proto)
fuzzer.importProgram(program, enableDropout: false, origin: .child(id: child))
} catch {
logger.warning("Received malformed program from child node: \(error)")
}

case .statistics:
if let data = try? Fuzzilli_Protobuf_Statistics(serializedData: data) {
if let data = try? Fuzzilli_Protobuf_Statistics(serializedBytes: data) {
if let stats = Statistics.instance(for: fuzzer) {
stats.importData(data, from: child)
}
Expand All @@ -267,7 +267,7 @@ public class DistributedFuzzingParentNode: DistributedFuzzingNode, Module {
}

case .log:
if let proto = try? Fuzzilli_Protobuf_LogMessage(serializedData: data),
if let proto = try? Fuzzilli_Protobuf_LogMessage(serializedBytes: data),
let origin = UUID(uuidString: proto.origin),
let level = LogLevel(rawValue: Int(clamping: proto.level)) {
fuzzer.dispatchEvent(fuzzer.events.Log, data: (origin: origin, level: level, label: proto.label, message: proto.content))
Expand Down Expand Up @@ -444,7 +444,7 @@ public class DistributedFuzzingChildNode: DistributedFuzzingNode, Module {
}

do {
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program(from: proto)

if messageType == .importedProgram {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Fuzzilli/Protobuf/ProtoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public func decodeProtobufCorpus(_ buffer: Data) throws -> [Program]{
}
let data = buffer.subdata(in: offset..<offset+size)
offset += size + align(size, to: 4)
let proto = try Fuzzilli_Protobuf_Program(serializedData: data)
let proto = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program(from: proto, opCache: opCache)
newPrograms.append(program)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FuzzilliCli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func loadCorpus(from dirPath: String) -> [Program] {
let path = dirPath + "/" + filename
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path))
let pb = try Fuzzilli_Protobuf_Program(serializedData: data)
let pb = try Fuzzilli_Protobuf_Program(serializedBytes: data)
let program = try Program.init(from: pb)
if !program.isEmpty {
programs.append(program)
Expand Down
6 changes: 3 additions & 3 deletions Tests/FuzzilliTests/ProgramSerializationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ProgramSerializationTests: XCTestCase {
let data1 = try! proto1.serializedData()
let data2 = try! proto2.serializedData()

proto1 = try! Fuzzilli_Protobuf_Program(serializedData: data1)
proto2 = try! Fuzzilli_Protobuf_Program(serializedData: data2)
proto1 = try! Fuzzilli_Protobuf_Program(serializedBytes: data1)
proto2 = try! Fuzzilli_Protobuf_Program(serializedBytes: data2)
XCTAssertEqual(proto1, proto2)

let copy1 = try! Program(from: proto1)
Expand Down Expand Up @@ -75,7 +75,7 @@ class ProgramSerializationTests: XCTestCase {

var proto = program.asProtobuf(opCache: encodingCache)
let data = try! proto.serializedData()
proto = try! Fuzzilli_Protobuf_Program(serializedData: data)
proto = try! Fuzzilli_Protobuf_Program(serializedBytes: data)
let copy = try! Program(from: proto, opCache: decodingCache)

XCTAssertEqual(program, copy)
Expand Down

0 comments on commit 7cb027f

Please sign in to comment.