Skip to content

Commit

Permalink
Land some new fuzz tests that fail finding the issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed May 1, 2024
1 parent 48fed8b commit 0cb8176
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Binary file not shown.
Binary file not shown.
34 changes: 26 additions & 8 deletions Tests/SwiftProtobufTests/Test_FuzzTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import Foundation
import XCTest

import SwiftProtobuf

final class Test_FuzzTests: XCTestCase {

func assertBinaryFails(_ bytes: [UInt8], file: XCTestFileArgType = #file, line: UInt = #line) {
Expand All @@ -43,35 +45,43 @@ final class Test_FuzzTests: XCTestCase {
file: file, line: line)
}

func assertTextFormatFails(_ textFormat: String, file: XCTestFileArgType = #file, line: UInt = #line) {
func assertTextFormatFails(_ textFormat: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
XCTAssertThrowsError(
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat,
options: options,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
file: file, line: line)
}

func assertTextFormatFails(_ asBytes: [UInt8], file: XCTestFileArgType = #file, line: UInt = #line) {
func assertTextFormatFails(_ asBytes: [UInt8], options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
guard let str = String(data: Data(asBytes), encoding: .utf8) else {
XCTFail("Failed to make a string", file: file, line: line)
return
}
XCTAssertThrowsError(
try SwiftProtoTesting_Fuzz_Message(textFormatString: str, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
try SwiftProtoTesting_Fuzz_Message(textFormatString: str,
options: options,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
file: file, line: line)
}

func assertTextFormatSucceeds(_ textFormat: String, file: XCTestFileArgType = #file, line: UInt = #line) {
func assertTextFormatSucceeds(_ textFormat: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
XCTAssertNoThrow(
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat,
options: options,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
file: file, line: line)
}

func assertTextFormatSucceeds(_ asBytes: [UInt8], file: XCTestFileArgType = #file, line: UInt = #line) {
func assertTextFormatSucceeds(_ asBytes: [UInt8], options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
guard let str = String(data: Data(asBytes), encoding: .utf8) else {
XCTFail("Failed to make a string", file: file, line: line)
return
}
XCTAssertNoThrow(
try SwiftProtoTesting_Fuzz_Message(textFormatString: str, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
try SwiftProtoTesting_Fuzz_Message(textFormatString: str,
options: options,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
file: file, line: line)
}

Expand Down Expand Up @@ -128,5 +138,13 @@ final class Test_FuzzTests: XCTestCase {
assertTextFormatSucceeds("500<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<[google.protobuf.Any]<>>>>>>>>>>>>>>>>500<1:''\n2:''>")

assertTextFormatFails("500<[fvwzz_exobuf.Aob/google.protobuf.Any]<[oeFgb/google.protobuf.Any]<[xlob/google.protobuf.Any]<[oeee0FFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<[oglob/google.protobuf.Any]<[oogoFFFFFFFFRFfuzz.tebool_extFFFFFFFBFFFFegleeeeeeeeeeeeeeeeeeemeeeeeeeeeeeneeeeeeeekeeeeFFFFFFFFFIFFFFFFFgb/google.protobuf.Any]<>>>>>>>>>>>>>>>>>500<1:''\n1:''\n1:''\n2:''\n1:'roto")

// FailCases/clusterfuzz-testcase-FuzzTextFormat_release-4619956026146816
// FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4619956026146816
var opts = TextFormatDecodingOptions()
opts.ignoreUnknownFields = true
opts.ignoreUnknownExtensionFields = true
assertTextFormatFails("rsingular_sint:-", options: opts)
assertTextFormatFails(" l :-", options: opts)
}
}

0 comments on commit 0cb8176

Please sign in to comment.