microsoft / plcrashreporter

Reliable, open-source crash reporting for iOS, macOS and tvOS
Other
2.84k stars 532 forks source link

AddressSanitizer: CHECK failed: sanitizer_posix.cpp:61 #279

Closed tamwei closed 3 months ago

tamwei commented 1 year ago

Description

When I enable Address Sanitizer and Detect use of stack after return, Xcode breakpoint with message:

==54244==ERROR: AddressSanitizer failed to deallocate 0x10000 (65536) bytes at address 0x000108028800 AddressSanitizer: CHECK failed: sanitizer_posix.cpp:61 "(("unable to unmap" && 0)) != (0)" (0x0, 0x0) (tid=2246838)

After I use memory history 0x000108028800 , I found that the problem may be caused by line 288 of PLCrashSignalHandler.mm (https://github.com/microsoft/plcrashreporter/blob/master/Source/PLCrashSignalHandler.mm#L288)

Repro Steps

  1. I enable Address Sanitizer and Detect use of stack after return

1681873296

  1. and then launching my app , after a while Xcode will breakpoint with the blow message:

1681873777

Details

  1. Which SDK version are you using? 1.11.0
  2. Which OS version did you experience the issue on? macOS 12.6 (M1)
  3. What device version did you see this error on? Were you using an emulator or a physical device? Xcode 14.1
aleksandr-dorofeev commented 1 year ago

Hi @tamwei Thank you for reporting the issue. Give us some time to take a look at this.

aleksandr-dorofeev commented 1 year ago

Hello @tamwei, unfortunately we were unable to reproduce the error message.

Could you share more information?

 How do you connect PLCrashReporter to your project?  How do you debug it?  Could you provide a sample app that reproduces this error message?

tamwei commented 1 year ago

hello @aleksandr-dorofeev, I probably know the reason for this issue, because I initialize PLCrashReporter in an asynchronous global queue.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{
      [self enableCrashReporter];
    });

}

- (void)enableCrashReporter {
    if(_crashReporter) {
        return;
    }
    PLCrashReporterSignalHandlerType handleType = PLCrashReporterSignalHandlerTypeBSD;
    PLCrashReporterSymbolicationStrategy strategy = PLCrashReporterSymbolicationStrategySymbolTable;
    PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:handleType symbolicationStrategy:strategy shouldRegisterUncaughtExceptionHandler:YES];
    _crashReporter = [[PLCrashReporter alloc] initWithConfiguration:config];

    NSError *error;
    PLCrashReporterCallbacks cb = {
        .version = 0,
        .context = (void *)0xABABABAB,
        .handleSignal = callbackSigHandler};
    [self.crashReporter setCrashCallbacks:&cb];

    if (![self.crashReporter enableCrashReporterAndReturnError:&error]) {
        NSLog(@"error:%@",error);
    }
}

And then I verified the code below. After the app starts, I switch between other programs and this app many times (let them get the focus), and the above issue will still be triggered.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{
        self->_sigstk.ss_size = SIGSTKSZ;
        self->_sigstk.ss_sp = malloc(self->_sigstk.ss_size);
        self->_sigstk.ss_flags = 0;

        sigaltstack(&self->_sigstk, 0);
    });

}
aleksandr-dorofeev commented 1 year ago

Thanks for the additional information. Could you please clarify how you add PLCrashReporter to your project? Using SPM/Carthage/CocoaPods?

tamwei commented 1 year ago

Sorry for the late reply. I downloaded PLCrashReporter from here and manually added it to the sample below.

Sample.zip

aleksandr-dorofeev commented 1 year ago

Thanks for providing the sample app. It turned out to reproduce the error on our side. We've filed an item on our internal board for this request. Will update this thread once got results.

tamwei commented 1 year ago

@aleksandr-dorofeev Thank you every much.

DmitriyKirakosyan commented 3 months ago

As we do not have plans to fix this bug in the next year, I'm closing the issue.