Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Crash when logging invalid characters #662

Closed
bagage opened this issue Feb 3, 2016 · 7 comments
Closed

Crash when logging invalid characters #662

bagage opened this issue Feb 3, 2016 · 7 comments
Labels

Comments

@bagage
Copy link

bagage commented Feb 3, 2016

Using master version, tests are crashing consistently when invoked from Jenkins using XCode7.2 (SDK 9:2). Before updating to master, I was getting crashes similar to #555 and #650. I am/was also affected by #623 hence I had to strip XML after xctool completed, so there was always an issue with bad characters I am dumping in logs. Any clue? (except of removing logs!).

xctool[40242:16271961] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff8e17503c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8f30676e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8e020329 -[__NSArrayM insertObject:atIndex:] + 1033
    3   xctool                              0x0000000101a4cdd4 __ReadOutputsAndFeedOuputLinesToBlockOnQueue_block_invoke15 + 578
    4   xctool                              0x0000000101a4d056 __ReadOutputsAndFeedOuputLinesToBlockOnQueue_block_invoke_239 + 178
    5   libdispatch.dylib                   0x00007fff854cf7ab ___dispatch_operation_deliver_data_block_invoke + 118
    6   libdispatch.dylib                   0x00007fff854bc323 _dispatch_call_block_and_release + 12
    7   libdispatch.dylib                   0x00007fff854b7c13 _dispatch_client_callout + 8
    8   libdispatch.dylib                   0x00007fff854bb365 _dispatch_queue_drain + 1100
    9   libdispatch.dylib                   0x00007fff854bcecc _dispatch_queue_invoke + 202
    10  libdispatch.dylib                   0x00007fff854bb154 _dispatch_queue_drain + 571
    11  libdispatch.dylib                   0x00007fff854bcecc _dispatch_queue_invoke + 202
    12  libdispatch.dylib                   0x00007fff854ba6b7 _dispatch_root_queue_drain + 463
    13  libdispatch.dylib                   0x00007fff854c8fe4 _dispatch_worker_thread3 + 91
    14  libsystem_pthread.dylib             0x00007fff83db8a9d _pthread_wqthread + 729
    15  libsystem_pthread.dylib             0x00007fff83db63dd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@ExtremeMan ExtremeMan added the bug label Feb 4, 2016
@ExtremeMan
Copy link
Contributor

Can you write a simple test case which will cause this crash? I would really appreciate so I can iterate on it and fix xctool eventually.

@ExtremeMan
Copy link
Contributor

But most likely crash is hit at this line: https://github.com/facebook/xctool/blob/master/Common/TaskUtil.m#L127.
Can you try wrapping it into if (line) { [lines addObject:line]; }

@bagage
Copy link
Author

bagage commented Feb 4, 2016

Thanks for the hint @ExtremeMan . A few notes:

  • bug is not 100% reproducible. Probably because it depends on the characters I am dumping which vary from time to time (dumping ZIP network data). I get exceptions around 40% of the time.
  • I cannot reproduce the bug if I attach Xcode debugger to xctool. So that's a bit annoying... :(
  • The bug seems only present on one of my 2 machines.
  • Your work-around fixes the issue, indeed line is nil.

I will continue my investigation until I catch the string causing the exception, but at least there is a work-around for now. I'll let you know when I have a simple test for it.

@bagage
Copy link
Author

bagage commented Feb 5, 2016

I am able to reproduce the bug with this quick&dirty test:

static void dummy_test(void){
    FILE*fp = fopen("/tmp/test.txt", "r");
    if (fp) {
        char *line = NULL;
        size_t linecap = 0;
        ssize_t linelen;
        while ((linelen = getline(&line, &linecap, fp)) > 0)
            fprintf(stderr, "%s\n", line);
        fclose(fp);
    }
}

With test.txt.

Interesting enough: copying/pasting file content in a variable and escaping quotes lead to no exception.

@ExtremeMan
Copy link
Contributor

Thanks for the example. I am able to reproduce locally. iconv fails actually. I will have some workaround for such use cases but most likely xctool will just print empty string in that case.

@ExtremeMan
Copy link
Contributor

Can you try this branch for me - https://github.com/facebook/xctool/tree/nekto/utf8_handling?

@bagage
Copy link
Author

bagage commented Feb 8, 2016

Yep, it solves the issue!

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

No branches or pull requests

2 participants