Repository navigation
fix: Don't crash when decoding an out-of-range Timestamp string - #123
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes a crash when decoding out-of-range timestamp strings by replacing try! with try during parsing, and adds corresponding unit tests. The review feedback suggests wrapping the raw SwiftProtobuf error in a domain-specific DataConnectCodecError.invalidTimestampFormat error to avoid leaking implementation details of the underlying library.
|
LGTM |
|
Thanks for the fix PR @dmorfav !! |
Thanks for the review! The workflow runs (check, spm) are waiting for maintainer approval since this is my first contribution from a fork. |
|
@aashishpatil-g the CI failure is unrelated to this change: FYI @paulb777 |
|
Yes, the CI failure is unrelated. |
|
I’m keeping an eye on PR #124 so I can update mine once it’s merged. |
…ed-string-crash # Conflicts: # CHANGELOG.md
|
@aashishpatil-g this PR is also green and ready for review! |
|
LGTM - resolved the CHANGELOG conflict. |
Fixes firebase/firebase-ios-sdk#16888
Timestamp.init(from:)checks the string format with a regex but not the ranges, then parses it withtry! Google_Protobuf_Timestamp(jsonString:). Strings like"2026-13-01T00:00:00Z"pass the regex, SwiftProtobuf rejects them, and thetry!crashes the process. SinceAnyCodableValuetriesTimestampfirst for every JSON string, oneStringfield with such a value crashes the app while it caches the server response, and also whenAnyValuedecodes it.Change
CodableTimestamp:try!→tryininit(from:), which alreadythrows. Decoding asTimestampnow throws, andAnyCodableValuefalls back to.stringthrough its existingtry?.Tests
TimestampCodableTestsgets two new tests, with six values that match the regex but are out of range:testOutOfRangeValuesShouldThrowtestOutOfRangeValuesInAnyValueAreKeptAsStringsWithout the fix, both crash with
Fatal error: 'try!' expression unexpectedly raised an error. With the fix,swift test --filter FirebaseDataConnectUnitpasses (82 tests), and so doesscripts/style.sh test-only.This PR is independent of #122: the two touch different lines. The only overlap is the
# Unreleasedheading in the CHANGELOG.