Skip to content

Commit 0cb8176

Browse files
committed
Land some new fuzz tests that fail finding the issues.
1 parent 48fed8b commit 0cb8176

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed
Binary file not shown.

Tests/SwiftProtobufTests/Test_FuzzTests.swift

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import Foundation
2424
import XCTest
2525

26+
import SwiftProtobuf
27+
2628
final class Test_FuzzTests: XCTestCase {
2729

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

46-
func assertTextFormatFails(_ textFormat: String, file: XCTestFileArgType = #file, line: UInt = #line) {
48+
func assertTextFormatFails(_ textFormat: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
4749
XCTAssertThrowsError(
48-
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
50+
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat,
51+
options: options,
52+
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
4953
file: file, line: line)
5054
}
5155

52-
func assertTextFormatFails(_ asBytes: [UInt8], file: XCTestFileArgType = #file, line: UInt = #line) {
56+
func assertTextFormatFails(_ asBytes: [UInt8], options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
5357
guard let str = String(data: Data(asBytes), encoding: .utf8) else {
5458
XCTFail("Failed to make a string", file: file, line: line)
5559
return
5660
}
5761
XCTAssertThrowsError(
58-
try SwiftProtoTesting_Fuzz_Message(textFormatString: str, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
62+
try SwiftProtoTesting_Fuzz_Message(textFormatString: str,
63+
options: options,
64+
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
5965
file: file, line: line)
6066
}
6167

62-
func assertTextFormatSucceeds(_ textFormat: String, file: XCTestFileArgType = #file, line: UInt = #line) {
68+
func assertTextFormatSucceeds(_ textFormat: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
6369
XCTAssertNoThrow(
64-
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
70+
try SwiftProtoTesting_Fuzz_Message(textFormatString: textFormat,
71+
options: options,
72+
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
6573
file: file, line: line)
6674
}
6775

68-
func assertTextFormatSucceeds(_ asBytes: [UInt8], file: XCTestFileArgType = #file, line: UInt = #line) {
76+
func assertTextFormatSucceeds(_ asBytes: [UInt8], options: TextFormatDecodingOptions = TextFormatDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line) {
6977
guard let str = String(data: Data(asBytes), encoding: .utf8) else {
7078
XCTFail("Failed to make a string", file: file, line: line)
7179
return
7280
}
7381
XCTAssertNoThrow(
74-
try SwiftProtoTesting_Fuzz_Message(textFormatString: str, extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
82+
try SwiftProtoTesting_Fuzz_Message(textFormatString: str,
83+
options: options,
84+
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions),
7585
file: file, line: line)
7686
}
7787

@@ -128,5 +138,13 @@ final class Test_FuzzTests: XCTestCase {
128138
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:''>")
129139

130140
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")
141+
142+
// FailCases/clusterfuzz-testcase-FuzzTextFormat_release-4619956026146816
143+
// FailCases/clusterfuzz-testcase-minimized-FuzzTextFormat_release-4619956026146816
144+
var opts = TextFormatDecodingOptions()
145+
opts.ignoreUnknownFields = true
146+
opts.ignoreUnknownExtensionFields = true
147+
assertTextFormatFails("rsingular_sint:-", options: opts)
148+
assertTextFormatFails(" l :-", options: opts)
131149
}
132150
}

0 commit comments

Comments
 (0)