Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Metadata Parse Crash #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

biklas7
Copy link
Contributor

@biklas7 biklas7 commented Jan 20, 2025

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: NSInternalInconsistencyException

0 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 and sanitizeArray 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.

@biklas7
Copy link
Contributor Author

biklas7 commented Jan 20, 2025

We are running a fork to mitigate this, but we do get some crashes among our users so it would be great if @bardram or @iarata or someone else could look into this and if ok publish a fix 🙏

@iarata
Copy link
Contributor

iarata commented Jan 20, 2025

Thanks for the PR! I will check it this week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants