Skip to content

Commit f50413e

Browse files
committed
fix: Safer asset catalog reader for liquid glass
1 parent 6ff97bd commit f50413e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

apple-catalog-parsing/native/swift/AssetCatalogParser/Sources/AssetCatalogParser/AssetCatalogReader.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ enum AssetUtil {
8484
key.perform(Selector(("keyList"))),
8585
to: UnsafeMutableRawPointer.self
8686
)
87-
let rendition = createRendition(from: structuredThemeStore, keyList)
87+
guard let rendition = createRendition(from: structuredThemeStore, keyList) else {
88+
continue
89+
}
8890

8991
let data = rendition.value(forKey: "_srcData") as! Data
9092
let length = UInt(data.count)
@@ -198,13 +200,13 @@ enum AssetUtil {
198200
}
199201

200202
private static func createRendition(from themeStore: NSObject, _ keyList: UnsafeMutableRawPointer)
201-
-> NSObject
203+
-> NSObject?
202204
{
203205
let renditionWithKeySelector = Selector(("renditionWithKey:"))
204206
let renditionWithKeyMethod = themeStore.method(for: renditionWithKeySelector)!
205207
let renditionWithKeyImp = unsafeBitCast(renditionWithKeyMethod, to: objectiveCMethodImp.self)
206-
return renditionWithKeyImp(themeStore, renditionWithKeySelector, keyList)!.takeUnretainedValue()
207-
as! NSObject
208+
return renditionWithKeyImp(themeStore, renditionWithKeySelector, keyList)?.takeUnretainedValue()
209+
as? NSObject
208210
}
209211

210212
private static func handleReferenceKey(
@@ -222,7 +224,9 @@ enum AssetUtil {
222224
referenceKey.perform(Selector(("keyList"))),
223225
to: UnsafeMutableRawPointer.self
224226
)
225-
let referenceRendition = createRendition(from: themeStore, referenceKeyList)
227+
guard let referenceRendition = createRendition(from: themeStore, referenceKeyList) else {
228+
return false
229+
}
226230

227231
if let result = referenceRendition.perform(Selector(("unslicedImage"))) {
228232
let image = result.takeUnretainedValue() as! CGImage

0 commit comments

Comments
 (0)