Skip to content

Commit

Permalink
Increment GDT's version and CHANGELOG (#3691)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mikehaney24 authored and paulb777 committed Aug 26, 2019
1 parent f00f8ce commit 69640b5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GoogleDataTransport.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GoogleDataTransport'
s.version = '1.1.2'
s.version = '1.1.3'
s.summary = 'Google iOS SDK data transport.'

s.description = <<-DESC
Expand Down
3 changes: 3 additions & 0 deletions GoogleDataTransport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v1.1.3
- Wrap decoding in GDTUploadCoordinator in a try catch. (#3676)

# v1.1.2
- Add initial support for iOS 13.
- Add initial support for Catalyst.
Expand Down
15 changes: 11 additions & 4 deletions GoogleDataTransport/GDTLibrary/GDTUploadCoordinator.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,23 @@ + (BOOL)supportsSecureCoding {

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
GDTUploadCoordinator *sharedCoordinator = [GDTUploadCoordinator sharedInstance];
sharedCoordinator->_targetToInFlightPackages =
[aDecoder decodeObjectOfClass:[NSMutableDictionary class]
forKey:ktargetToInFlightPackagesKey];
@try {
sharedCoordinator->_targetToInFlightPackages =
[aDecoder decodeObjectOfClass:[NSMutableDictionary class]
forKey:ktargetToInFlightPackagesKey];

} @catch (NSException *exception) {
sharedCoordinator->_targetToInFlightPackages = [NSMutableDictionary dictionary];
}
return sharedCoordinator;
}

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

#pragma mark - GDTLifecycleProtocol
Expand Down
12 changes: 12 additions & 0 deletions GoogleDataTransport/GDTTests/Unit/GDTUploadCoordinatorTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,16 @@ - (void)testThatAFailedUploadResultsInAnEventualRetry {
});
}

/** Tests that encoding and decoding works without crashing. */
- (void)testNSSecureCoding {
GDTUploadPackage *package = [[GDTUploadPackage alloc] initWithTarget:kGDTTargetTest];
GDTUploadCoordinator *coordinator = [[GDTUploadCoordinator alloc] init];
coordinator.targetToInFlightPackages[@(kGDTTargetTest)] = package;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:coordinator];

// Unarchiving the coordinator always ends up altering the singleton instance.
GDTUploadCoordinator *unarchivedCoordinator = [NSKeyedUnarchiver unarchiveObjectWithData:data];
XCTAssertEqualObjects([GDTUploadCoordinator sharedInstance], unarchivedCoordinator);
}

@end

0 comments on commit 69640b5

Please sign in to comment.