Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was the contributor that added Insulin Delivery capabilities to this package via #675 and we've been using this package a lot in our app.
Since there are lots of sources to read Insulin Deliver from, sometimes the Apple Health metadata might contain types that the FlutterStandardCodec does not support causing crashes like this when reading and passing the metadata map directly.
Crash report
Fatal Exception: NSInternalInconsistencyException0 CoreFoundation 0x2d5ec __exceptionPreprocess
1 libobjc.A.dylib 0x31244 objc_exception_throw
2 Foundation 0x82dff0 -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:]
3 Flutter 0x5e6ca4 WriteValueOfType(void const*, __CFData*, FlutterStandardCodecObjcType, void const*) + 341 (FlutterStandardCodec.mm:341)
4 Flutter 0x5e692c -[FlutterStandardWriter writeValue:] + 351 (FlutterStandardCodec.mm:351)
5 libswiftCore.dylib 0x371fe0 specialized _SwiftDeferredNSDictionary.enumerateKeysAndObjects(options:using:)
6 libswiftCore.dylib 0xcb9b4 @objc _SwiftDeferredNSDictionary.enumerateKeysAndObjects(options:using:)
7 CoreFoundation 0x80eb4 -[NSDictionary __apply:context:]
8 Flutter 0x5e6db8 WriteValueOfType(void const*, __CFData*, FlutterStandardCodecObjcType, void const*) + 335 (FlutterStandardCodec.mm:335)
9 CoreFoundation 0x23d84 -[__NSDictionaryI __apply:context:]
10 Flutter 0x5e6db8 WriteValueOfType(void const*, __CFData*, FlutterStandardCodecObjcType, void const*) + 335 (FlutterStandardCodec.mm:335)
11 Flutter 0x5e6ba4 WriteValueOfType(void const*, __CFData*, FlutterStandardCodecObjcType, void const*) + 321 (FlutterStandardCodec.mm:321)
12 Flutter 0x5e692c -[FlutterStandardWriter writeValue:] + 351 (FlutterStandardCodec.mm:351)
13 Flutter 0x5e7b74 -[FlutterStandardMethodCodec encodeSuccessEnvelope:] + 95 (FlutterStandardCodec.mm:95)
14 Flutter 0x5e239c __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke_2 + 319 (FlutterChannels.mm:319)
15 health 0x9868 (Missing UUID d0bdff31a3eb323497b1a36ebf2d1b3c)
16 health 0x2b6a0 (Missing UUID d0bdff31a3eb323497b1a36ebf2d1b3c)
17 health 0xb6c0 (Missing UUID d0bdff31a3eb323497b1a36ebf2d1b3c)
18 libdispatch.dylib 0x2248 _dispatch_call_block_and_release
19 libdispatch.dylib 0x3fa8 _dispatch_client_callout
20 libdispatch.dylib 0x12a34 _dispatch_main_queue_drain
21 libdispatch.dylib 0x1264c _dispatch_main_queue_callback_4CF
22 CoreFoundation 0x79bbc CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
23 CoreFoundation 0x761b0 __CFRunLoopRun
24 CoreFoundation 0xc8274 CFRunLoopRunSpecific
25 GraphicsServices 0x14c0 GSEventRunModal
26 UIKitCore 0x3ee77c -[UIApplication _run]
27 UIKitCore 0x14e64 UIApplicationMain
28 UIKitCore 0x751a7c keypath_get_selector_hoverStyle
29 Runner 0x98c0 main (AppDelegate.swift)
30 ??? 0x1c3028de8 (Missing)
In short, this change introduces the
sanitizeMetadata
andsanitizeArray
whose only job is to parse only supported types from the metadata and ignore the rest, making metadata safe to be sent across method channels.Like so I've updated the way we extract the metadata from HKQuantitySample and HKCategorySample samples as it was the only place were we do this.