emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 422 forks source link

CocoaMQTTStorage.swift line 129 CocoaMQTTStorage.__read(needDelete:) iOS 14 #340

Open UditHD opened 4 years ago

UditHD commented 4 years ago

App is crashing for iOS 14 beta version Crash log:- Crashed: com.apple.main-thread 0 CocoaMQTT 0x105cb7cf4 CocoaMQTTStorage._read(needDelete:) + 129 (CocoaMQTTStorage.swift:129) 1 CocoaMQTT 0x105cad500 CocoaMQTTDeliver.recoverSessionBy(:) + 88 (CocoaMQTTStorage.swift:88) 2 CocoaMQTT 0x105caafe8 specialized CocoaMQTT.didRecevied(:connack:) + 1320 (:1320) 3 CocoaMQTT 0x105cb43fc CocoaMQTTReader.frameReady() + 1628 (:1628) 4 CocoaMQTT 0x105cb3d70 CocoaMQTTReader.payloadReady(:) + 89 (CocoaMQTTReader.swift:89) 5 CocoaMQTT 0x105ca5224 CocoaMQTT.socket(:didRead:withTag:) + 583 (CocoaMQTT.swift:583) 6 CocoaMQTT 0x105cb5ec8 @objc CocoaMQTTSocket.socket(:didRead:withTag:) + 128 (CocoaMQTTSocket.swift:128) 7 CocoaAsyncSocket 0x105c468d8 __37-[GCDAsyncSocket completeCurrentRead]_block_invoke + 5767 (GCDAsyncSocket.m:5767) 8 libdispatch.dylib 0x188134410 + 32 9 libdispatch.dylib 0x188135f08 + 20 10 libdispatch.dylib 0x188143480 _dispatch_main_queue_callback_4CF + 836 11 CoreFoundation 0x188416d2c + 16 12 CoreFoundation 0x18841132c + 1940 13 CoreFoundation 0x188410788 CFRunLoopRunSpecific + 564 14 GraphicsServices 0x1942eb820 GSEventRunModal + 164 15 UIKitCore 0x18cbcf1d8 + 1072 16 UIKitCore 0x18cbd50b8 UIApplicationMain + 1876

adicatur commented 4 years ago

Good morning @HJianBo, face this issue on 1.3.0-rc.1 kindly check

thanks

Lakshaya commented 4 years ago

@HJianBo this issue is creating problem for out users please check this in priority.

UditHD commented 3 years ago

@HJianBo seems like this issue is happening due to cleanSession, we able to figured out that this issue not comes on setting cleansession = true

filippocamillo commented 3 years ago

Hello, any progress on this issue? I have a customer out there with the very same issue.

Thanks

leeway1208 commented 3 years ago

hi, please provide some detailed operations which leads to this error.

sainttail commented 2 years ago

I also got this crash and luckily it occurs on one of the colleague device so I'm able to debug.

This is the data I got in allObjs on line. The problematic key is ApplePerAppLanguageSelectionBundleIdentifiers which return empty array.

[(key: "AKDeviceUnlockState", value: 1), (key: "AKLastCheckInAttemptDate", value: 2019-10-06 03:01:23 +0000), (key: "AKLastCheckInSuccessDate", value: 2019-10-06 03:01:25 +0000), (key: "AKLastEmailListRequestDateKey", value: 2022-02-09 01:35:03 +0000), (key: "AKLastIDMSEnvironment", value: 0), (key: "ActivePrototypingEnabled", value: 0), (key: "AddingEmojiKeybordHandled", value: 1), (key: "AppleKeyboards", value: <__NSCFArray 0x281299860>(
en_US@sw=QWERTY;hw=Automatic,
emoji@sw=Emoji,
th_TH@sw=Thai;hw=Automatic
)
), (key: "AppleKeyboardsExpanded", value: 1), (key: "AppleLanguages", value: <__NSCFArray 0x281299810>(
en-GB,
de-GB,
th-GB
)
), (key: "AppleLanguagesDidMigrate", value: 18F72), (key: "AppleLanguagesSchemaVersion", value: 2000), (key: "AppleLocale", value: en_GB), (key: "ApplePasscodeKeyboards", value: <__NSCFArray 0x28249e200>(
en_US@hw=Automatic;sw=QWERTY,
emoji@sw=Emoji
)
), (key: "ApplePerAppLanguageSelectionBundleIdentifiers", value: <__NSCFArray 0x283f9e520>(

)
), (key: "AppleTemperatureUnit", value: Celsius), (key: "CarCapabilities", value: {
    CarCapabilitiesDefaultIdentifier =     {
        CRCapabilitiesDisabledFeatureKey = 0;
        CRCapabilitiesUserInterfaceStyleKey = 2;
        CapabilitiesDashboardRoundedCornersKey = "{{0, 0}, {0, 0}}";
        CapabilitiesNowPlayingAlbumArtKey = 2;
        CapabilitiesViewAreaInsetKey = "{{0, 0}, {0, 0}}";
    };
}), (key: "ClearPrototypeCachesForMigration", value: 0), (key: "ClearSettingsArchivesForMigration", value: 0), (key: "INNextFreshmintRefreshDateKey", value: 666096358.280228), (key: "INNextHearbeatDate", value: 666343828.118071), (key: "MSVLoggingMasterSwitchEnabledKey", value: 0), (key: "NSAllowsDefaultLineBreakStrategy", value: 1), (key: "NSInterfaceStyle", value: macintosh), (key: "NSLanguages", value: <__NSArrayI 0x283f9de60>(
en-GB,
de-GB,
th-GB,
en
)
), (key: "PKEnableStockholmSettings", value: 1), (key: "PKKeychainVersionKey", value: 8), (key: "PKLogNotificationServiceResponsesKey", value: 0), (key: "PrototypeSettingsEnabled", value: 0), (key: "RemotePrototypingEnabled", value: 0), (key: "RingerSwitchShowsUI", value: 0), (key: "TestRecipeEatsRingerSwitch", value: 0), (key: "TestRecipeEatsVolumeDown", value: 0), (key: "TestRecipeEatsVolumeUp", value: 0), (key: "VolumeDownShowsUI", value: 0), (key: "VolumeUpShowsUI", value: 1), (key: "WebKitJSCFTLJITEnabledDefaultsKey", value: 1), (key: "WebKitJSCJITEnabledDefaultsKey", value: 1), (key: "WebKitShowLinkPreviews", value: 0), (key: "com.apple.Animoji.StickerRecents.SplashVersion", value: 1), (key: "com.apple.content-rating.AppRating", value: 1000), (key: "com.apple.content-rating.ExplicitBooksAllowed", value: 1), (key: "com.apple.content-rating.ExplicitMusicPodcastsAllowed", value: 1), (key: "com.apple.content-rating.MovieRating", value: 1000), (key: "com.apple.content-rating.TVShowRating", value: 1000), (key: "version", value: 3.1.1)]

With below code the crash is gone

private func parse(_ bytes: [UInt8]) -> (UInt8, [UInt8])? {
     /// bytes 1..<5 may be 'Remaining Length'

     // Add below check
     if bytes.count < 5 {
         return nil
     }

     for i in 1 ..< 5 {
         if (bytes[i] & 0x80) == 0 {
              return (bytes[0], Array(bytes.suffix(from: i+1)))
          }  
     }
     return nil
 }

Below is the stack trace

Screen Shot 2565-02-09 at 17 20 15
leeway1208 commented 2 years ago

@sainttail WOW, appreciate your idea and support ,and thank you for letting me know the reason. I just fixed yesterday.

sainttail commented 2 years ago

@leeway1208 You got the correct fixed!. It looks dubious accessing array without checking but at first I thought this is a strict specification of mqtt and it guarantees to always have value but yeah it crashes.

When this fix will be release? Thanks.

leeway1208 commented 2 years ago

I have released it 😄

niralishaha25 commented 2 years ago

is it released in version 2.0.3-beta3? Can you confirm when the fix would be released in stable release and not beta version?