Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range check timestamps on all parsing paths. #1686

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"wktTimestamp":"9999-12-31T23:59:60Z"}
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ private func parseTimestamp(s: String) throws -> (Int64, Int32) {
adjusted += Int64(hourOffset) * Int64(3600)
adjusted += Int64(minuteOffset) * Int64(60)
}
if adjusted < minTimestampSeconds || adjusted > maxTimestampSeconds {
throw JSONDecodingError.malformedTimestamp
}
seconds = adjusted
pos += 6
} else if value[pos] == letterZ { // "Z" indicator for UTC
Expand All @@ -181,6 +178,9 @@ private func parseTimestamp(s: String) throws -> (Int64, Int32) {
if pos != value.count {
throw JSONDecodingError.malformedTimestamp
}
guard seconds >= minTimestampSeconds && seconds <= maxTimestampSeconds else {
throw JSONDecodingError.malformedTimestamp
}
return (seconds, nanos)
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/SwiftProtobufTests/Test_FuzzTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ final class Test_FuzzTests: XCTestCase {
// This actually fails when the fuzzer was trying to write it back out again.
let msg = try! SwiftProtoTesting_Fuzz_Message(jsonString: " {\"wktAny\": {}} ")
XCTAssertEqual(try! msg.jsonString(), "{\"wktAny\":{}}")

// FailCases/clusterfuzz-testcase-minimized-FuzzJSON_debug-6286338012282880
assertJSONFails("{\"wktTimestamp\":\"9999-12-31T23:59:60Z\"}")
}

func test_TextFormat() {
Expand Down