Search code examples
objective-cmacosmacos-high-sierra

NSTask crashing with EXC_SOFTWARE exception on OSX High Sierra


I have a mac OSX app that used to use system() to run some ImageMagick commands - but suddenly these calls have started crashing with an

EXC_SOFTWARE (code=131072,subcode 0x0)

The only things I can think of that has changed recently is I upgraded to High Sierra and then Xcode updated itself to 10.0 - so perhaps one of these could be something to do with it.

So for example if I try:

system("ls -l");

or

NSTask *task = [[NSTask alloc] init];
task.executableURL = [NSURL fileURLWithPath:@"/bin/bash"];
[task setArguments:@[ @"-c", @"ls -l"]];
NSError *error=nil;
[task launchAndReturnError:&error];
[task waitUntilExit];

then in both cases I get this crash. And in both cases I can see a bit of the directory listing output appear in the log before the crash happens.

The crash happens when not trying to run bash as well - If I try and run /bin/ls directly from NSTask I get the same crash.

These commands normally run on a background GCD queue - but I have tried them on the main queue as well and they still crash.

When I run my ImageMagick code using NSTask the command completes and outputs the image it is supposed to but then I get the same crash (BTW this is why I'm running the commands via bash because IM starts up ghostscript and needs paths to be set to work properly).

So it looks like these commands are completing and then something else is happening to cause the crash once the command has completed.

Here is the console backtrace (including the partial output of the ls -l command) of it crashing when running the NSTask version of doing the ls -l shown above in the loadView of the main ViewController:

total 8
drwxr-xr-x  3 simon  staff    96 Sep 26 15:44 Database.app
-rw-r--r--  1 simon  staff  2219 Sep 27 13:23 00000001_01.png
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_SOFTWARE (code=131072, subcode=0x0)
  * frame #0: 0x00007fff6598193e libsystem_kernel.dylib`__posix_spawn + 10
    frame #1: 0x00007fff6597ae67 libsystem_kernel.dylib`posix_spawn + 483
    frame #2: 0x00007fff3fc42230 Foundation`-[NSConcreteTask launchWithDictionary:error:] + 3510
    frame #3: 0x000000010000f430 FanfugaDatabase`-[ViewController viewDidLoad](self=0x00006040000e2200, _cmd="viewDidLoad") at ViewController.m:45
    frame #4: 0x00007fff3af1c20a AppKit`-[NSViewController _sendViewDidLoad] + 97
    frame #5: 0x00007fff3b4c0afd AppKit`_noteLoadCompletionForObject + 641
    frame #6: 0x00007fff3aea097d AppKit`-[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 2042
    frame #7: 0x00007fff3af9bd1e AppKit`-[NSNib _instantiateNibWithExternalNameTable:options:] + 679
    frame #8: 0x00007fff3af9b97a AppKit`-[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136
    frame #9: 0x00007fff3af9ac50 AppKit`-[NSViewController loadView] + 343
    frame #10: 0x00007fff3af12a9e AppKit`-[NSViewController _loadViewIfRequired] + 75
    frame #11: 0x00007fff3af12a09 AppKit`-[NSViewController view] + 30
    frame #12: 0x00007fff3b091365 AppKit`-[NSWindow _contentViewControllerChanged] + 109
    frame #13: 0x00007fff3fa7de8e Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:] + 331
    frame #14: 0x00007fff3b0d40c5 AppKit`-[NSWindow setValue:forKey:] + 111
    frame #15: 0x00007fff3b0d4029 AppKit`-[NSIBUserDefinedRuntimeAttributesConnector establishConnection] + 637
    frame #16: 0x00007fff3aea0719 AppKit`-[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1430
    frame #17: 0x00007fff3af9bd1e AppKit`-[NSNib _instantiateNibWithExternalNameTable:options:] + 679
    frame #18: 0x00007fff3af9b97a AppKit`-[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136
    frame #19: 0x00007fff3b6f246c AppKit`-[NSStoryboard instantiateControllerWithIdentifier:] + 236
    frame #20: 0x00007fff3ae94a27 AppKit`NSApplicationMain + 729
    frame #21: 0x0000000100012262 Database`main(argc=3, argv=0x00007ffeefbff4f8) at main.m:12
    frame #22: 0x00007fff65831015 libdyld.dylib`start + 1
    frame #23: 0x00007fff65831015 libdyld.dylib`start + 1
(lldb) 

As requested I tried creating a plain command line app:

int main(int argc, const char * argv[]) {
    printf("Hello, World!\n");
    system("ls -l");
    return 0;
}

and this crashed with the same exception:

Hello, World!
total 56
-rwxr-xr-x  1 simon  staff  27680 Oct  1 21:34 test
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_SOFTWARE (code=131072, subcode=0x0)
  * frame #0: 0x00007fff6598193e libsystem_kernel.dylib`__posix_spawn + 10
    frame #1: 0x00007fff6597ae67 libsystem_kernel.dylib`posix_spawn + 483
    frame #2: 0x00007fff658fc9b1 libsystem_c.dylib`system + 407
    frame #3: 0x0000000100000f56 test`main(argc=1, argv=0x00007ffeefbff5e0) at main.c:14
    frame #4: 0x00007fff65831015 libdyld.dylib`start + 1
(lldb) 

UPDATE

If I run either the Cocoa app or the command line test executable directly from finder they work fine. So it is something to do with the app being launched from xCode (presumbly xCode 10.0 specifically) that is causing this issue.


Solution

  • This looked like this is an xCode 10 bug to me. Reported to a Apple and this was their response:

    We’re not familiar with the EXC_SOFTWARE signal, but searching online it appears to be involved with some anti-virus software. Do you have any installed on your Mac? You would likely need to ask the makers of that software if this is expected and if there are any workarounds. If it is possible to try disabling it to see if it reproduces, that may be instructive.

    I do have BitDefender running on my mac - removed it and hey presto this bug went away. So it is a BitDefender bug. Will report it to them.