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

crash with publishProperties #600

Open
fighting300 opened this issue Jul 5, 2024 · 2 comments
Open

crash with publishProperties #600

fighting300 opened this issue Jul 5, 2024 · 2 comments

Comments

@fighting300
Copy link

fighting300 commented Jul 5, 2024

hello, i find a crash when send message;
the ips info is blow:
example 1:
`
SIGSEGV: 0xffffff818ac549e0 0x0 + 6619471872

  • | $s11CommonKit_a21MqttPublishPropertiesC15correlationDataSays5UInt8VGSgvgTm
    0 | 0 0x0000000105c317c4 -[CKCrashReporter recordCrashWithSignal:]
    1 | 1 0x0000000105c347c8 SignalHandler
    2 | 2 libsystem_platform.dylib 0x00000001d29d429c _sigtramp
    3 | 3 libswiftCore.dylib 0xffffff818ac549e0 0x0 + 6619471872
    4 | 4 libswiftCore.dylib 0x000000018ac549e0 swift_retain
    5 | 5 libswiftCore.dylib 0x000000018ac90d60 swift_bridgeObjectRetain
    6 | 6 0x0000000104ebf28c $s11_a21MqttPublishPropertiesC15correlationDataSays5UInt8VGSgvgTm
    7 | 7 0x0000000104ebfc80 $s11_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg
    8 | 8 0x0000000104ec1454 $s11_a12FramePublishV15variableHeader5Says5UInt8VGyF
    9 | 9 0x0000000104ec138c $s11_a12FramePublishVAA0C0A2aDP15variableHeader5Says5UInt8VGyFTW
    10 | 10 0x0000000104ebae40 $s11_a5FramePAAE5bytes7versionSays5UInt8VGSS_tF
    11 | 11 0x0000000104eb7470 $s11CoKit_a10CocoaMQTT5C7deliver_10wantToSendyAA0C11MQTTDeliverC_AA5Frame_ptFTf4dnn_n
    12 | 12 0x0000000104ed7254 $s11CoKit_a16CocoaMQTTDeliverC7sendfun33_3A1FA28A55E8D3E9C161EBC734F6C95BLLyyAA5Frame_pFyyYbcfU_TATm


`

example 2:
`
SIGSEGV: 0x0000000101287e18 $s11CommonKit_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg

  • | $s11CoKit_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg
    0 | 0 0x0000000101ff97c4 -[CKCrashReporter recordCrashWithSignal:]
    1 | 1 0x0000000101ffc7c8 SignalHandler
    2 | 2 libsystem_platform.dylib 0x00000001f7de6290 _sigtramp
    3 | 3 0x0000000101287e18 $s11CoKit_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg
    4 | 4 0x0000000101287e18 $s11CoKit_a21MqttPublishPropertiesC10propertiesSays5UInt8VGvg
    5 | 5 0x0000000101289454 $s11CoKit_a12FramePublishV15variableHeader5Says5UInt8VGyF
    6 | 6 0x000000010128938c $s11CoKit_a12FramePublishVAA0C0A2aDP15variableHeader5Says5UInt8VGyFTW
    7 | 7 0x0000000101282e40 $s11CoKit_a5FramePAAE5bytes7versionSays5UInt8VGSS_tF
    8 | 8 0x000000010127f470 $s11CoKit_a10CocoaMQTT5C7deliver_10wantToSendyAA0C11MQTTDeliverC_AA5Frame_ptFTf4dnn_n
    9 | 9 0x000000010129f254 $s11CoKit_a16CocoaMQTTDeliverC7sendfun33_3A1FA28A55E8D3E9C161EBC734F6C95BLLyyAA5Frame_pFyyYbcfU_TATm


`

the code of mqtt is blow:

`

  • (instancetype)init {
    self = [super init];
    if (self) {
    self.pubProp = [[MqttPublishProperties alloc] initWithContentType:@"JSON"];
    }
    return self;
    }

  • (void)sendMessageData:(id)data ToTopic:(NSString *)topic userProperty:(nullable NSDictionary *)userInfo{
    dispatch_async(self.customQueue, ^{
    NSError *error = nil;
    NSString *dataStr = nil;
    // 将 NSDictionary,NSArray 再转为JSON 数据
    if([data isKindOfClass:[NSDictionary class]]||[data isKindOfClass:[NSArray class]]) {
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:&error];
    if (jsonData) {
    // 将 JSON 数据转换为字符串
    dataStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    }
    else if([data isKindOfClass:[NSString class]]) {
    dataStr = (NSString *)data;
    }

      [self.pubProp setUserProperty:userProps];
      
      if (dataStr && topic ) {
    
          NSInteger ret = [self.mqtt5 publish:topic withString:dataStr qos:CocoaMQTTQoSQos0 DUP:NO retained:NO properties:self.pubProp];
          if (ret == -1) {
               [MQTTClientManager reportMqttLogs:@{@"messageTopic": topic } withId:@"messageBlock" withTime:nil type:nil];
          }
      }
    

    });
    }
    `

how can this happen the "pubProps" is not release

it seems crash in blow code

` func properties() -> [UInt8] {

    // Properties
    return publishProperties?.properties ?? []
}


public var properties: [UInt8] {
    var properties = [UInt8]()

    //3.3.2.3.2  Payload Format Indicator
    if let payloadFormatIndicator = self.payloadFormatIndicator {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.payloadFormatIndicator.rawValue, value: [payloadFormatIndicator.rawValue])
    }
    //3.3.2.3.3  Message Expiry Interval
    if let messageExpiryInterval = self.messageExpiryInterval {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.willExpiryInterval.rawValue, value: messageExpiryInterval.byteArrayLittleEndian)
    }
    //3.3.2.3.4 Topic Alias
    if let topicAlias = self.topicAlias {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.topicAlias.rawValue, value: topicAlias.hlBytes)
    }
    //3.3.2.3.5 Response Topic
    if let responseTopic = self.responseTopic {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.responseTopic.rawValue, value: responseTopic.bytesWithLength)
    }
    //3.3.2.3.6 Correlation Data
    if let correlationData = self.correlationData {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.correlationData.rawValue, value: correlationData)
    }
    //3.3.2.3.7 Property Length User Property
    if let userProperty = self.userProperty {
        for (key, value) in userProperty {
            properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.userProperty.rawValue, value: key.bytesWithLength + value.bytesWithLength)
        }
    }
    //3.3.2.3.8 Subscription Identifier
    if let subscriptionIdentifier = self.subscriptionIdentifier,
       let subscriptionIdentifier = beVariableByteInteger(subscriptionIdentifier) {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.subscriptionIdentifier.rawValue, value: subscriptionIdentifier)
    }
    //3.3.2.3.9 Content Type
    if let contentType = self.contentType {
        properties += getMQTTPropertyData(type: CocoaMQTTPropertyName.contentType.rawValue, value: contentType.bytesWithLength)
    }


    

    return properties
}

`

@fighting300
Copy link
Author

@leeway1208 @HJianBo

@fighting300
Copy link
Author

image
Uploading 4eb03c20-39c4-106a-aaa1-910f0da557be.jpg…

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

No branches or pull requests

1 participant