Skip to content

Commit

Permalink
Fixes crash if you tried to save an object that didn't conform to NSS…
Browse files Browse the repository at this point in the history
…ecureCoding in user attributes
  • Loading branch information
yusuftor committed Aug 18, 2023
1 parent 1d33675 commit 7ed0ef2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The changelog for `SuperwallKit`. Also see the [releases](https://github.com/sup
### Fixes

- Fixes rare issue when using limits on a campaign rule. If a paywall encountered an error preventing it from being presented, it may still have been counted as having been presented. This would then have affected future paywall presentation requests underneath the same rule.
- Fixes issue where resources weren't being accessed correctly when installing the SDK via CocoaPods.
- Fixes issue where assets weren't being accessed correctly when installing the SDK via CocoaPods.
- Fixes crash if you tried to save an object that didn't conform to NSSecureCoding in user attributes.

## 3.3.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ extension PaywallViewController {
if isSafariVCPresented {
return
}
Task(priority: .utility) {
Task {
await trackClose()
}

Expand Down
24 changes: 22 additions & 2 deletions Sources/SuperwallKit/Storage/Cache/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,17 @@ class Cache {
return
}

let data = NSKeyedArchiver.archivedData(withRootObject: value)
guard let data = try? NSKeyedArchiver.archivedData(
withRootObject: value,
requiringSecureCoding: true
) else {
Logger.debug(
logLevel: .warn,
scope: .cache,
message: "Could not write object that doesn't conform to NSSecureCoding to cache."
)
return
}
memCache.setObject(data as AnyObject, forKey: keyType.key as AnyObject)

writeDataToDisk(
Expand All @@ -163,7 +173,17 @@ class Cache {
return
}

let archivedData = NSKeyedArchiver.archivedData(withRootObject: data)
guard let archivedData = try? NSKeyedArchiver.archivedData(
withRootObject: data,
requiringSecureCoding: true
) else {
Logger.debug(
logLevel: .warn,
scope: .cache,
message: "Could not write object that doesn't conform to NSSecureCoding to cache."
)
return
}
memCache.setObject(archivedData as AnyObject, forKey: keyType.key as AnyObject)

writeDataToDisk(
Expand Down

0 comments on commit 7ed0ef2

Please sign in to comment.