Skip to content

Commit 69640b5

Browse files
mikehaney24paulb777
authored andcommitted
Increment GDT's version and CHANGELOG (#3691)
* Increment GDT's version and CHANGELOG * Wrap decoding targetToInflightPackages in a try/catch (#3689) It's not apparent how a key could be stored with a nil object in the dictionary. Maybe it's possible that somehow a GDTUploadPackage fails to decode, but there aren't any indications that this is the case. This PR adds a check for contents of the dictionary, though encoding an empty dictionary should be fine. A try/catch is utilized to catch exceptions thrown in iOS's implementation of NSSecureCoding in NSMutableDictionary.
1 parent f00f8ce commit 69640b5

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

GoogleDataTransport.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'GoogleDataTransport'
3-
s.version = '1.1.2'
3+
s.version = '1.1.3'
44
s.summary = 'Google iOS SDK data transport.'
55

66
s.description = <<-DESC

GoogleDataTransport/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.1.3
2+
- Wrap decoding in GDTUploadCoordinator in a try catch. (#3676)
3+
14
# v1.1.2
25
- Add initial support for iOS 13.
36
- Add initial support for Catalyst.

GoogleDataTransport/GDTLibrary/GDTUploadCoordinator.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,23 @@ + (BOOL)supportsSecureCoding {
163163

164164
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
165165
GDTUploadCoordinator *sharedCoordinator = [GDTUploadCoordinator sharedInstance];
166-
sharedCoordinator->_targetToInFlightPackages =
167-
[aDecoder decodeObjectOfClass:[NSMutableDictionary class]
168-
forKey:ktargetToInFlightPackagesKey];
166+
@try {
167+
sharedCoordinator->_targetToInFlightPackages =
168+
[aDecoder decodeObjectOfClass:[NSMutableDictionary class]
169+
forKey:ktargetToInFlightPackagesKey];
170+
171+
} @catch (NSException *exception) {
172+
sharedCoordinator->_targetToInFlightPackages = [NSMutableDictionary dictionary];
173+
}
169174
return sharedCoordinator;
170175
}
171176

172177
- (void)encodeWithCoder:(NSCoder *)aCoder {
173178
// All packages that have been given to uploaders need to be tracked so that their expiration
174179
// timers can be called.
175-
[aCoder encodeObject:_targetToInFlightPackages forKey:ktargetToInFlightPackagesKey];
180+
if (_targetToInFlightPackages.count > 0) {
181+
[aCoder encodeObject:_targetToInFlightPackages forKey:ktargetToInFlightPackagesKey];
182+
}
176183
}
177184

178185
#pragma mark - GDTLifecycleProtocol

GoogleDataTransport/GDTTests/Unit/GDTUploadCoordinatorTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,16 @@ - (void)testThatAFailedUploadResultsInAnEventualRetry {
146146
});
147147
}
148148

149+
/** Tests that encoding and decoding works without crashing. */
150+
- (void)testNSSecureCoding {
151+
GDTUploadPackage *package = [[GDTUploadPackage alloc] initWithTarget:kGDTTargetTest];
152+
GDTUploadCoordinator *coordinator = [[GDTUploadCoordinator alloc] init];
153+
coordinator.targetToInFlightPackages[@(kGDTTargetTest)] = package;
154+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:coordinator];
155+
156+
// Unarchiving the coordinator always ends up altering the singleton instance.
157+
GDTUploadCoordinator *unarchivedCoordinator = [NSKeyedUnarchiver unarchiveObjectWithData:data];
158+
XCTAssertEqualObjects([GDTUploadCoordinator sharedInstance], unarchivedCoordinator);
159+
}
160+
149161
@end

0 commit comments

Comments
 (0)