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

Try and handle NSData UTF8 encoding failures in subliminal-instruments #231

Conversation

justinseanmartin
Copy link

The issue with the current logic is that it assumes that each individual data buffer will successfully convert into a UTF8 string. However, this is not the case if instruments flushes the pipe in the middle of a UTF8 multi-byte character, and will lead to an exception when we try to appendString:nil to buffer.

The easy solution to this crash is that if the data buffer doesn't convert, then wait for the next data buffer. The assumption is that before the pipe is closed, we'll receive a buffer that can be successfully converted.

FYI - One potential issue with this solution is that if the Instruments output has a lot of non-ASCII text in it, the data buffer will be more likely to fail conversion (and grow the buffer in memory while doing so). This is could possibly happen with a non-English localized app-under-test (e.g. Japanese). This could be even more problematic if the OSX system language were set to a different language.

@justinseanmartin justinseanmartin changed the title Try and handle NSData encoding failures Try and handle NSData UTF8 encoding failures in subliminal-instruments Jul 10, 2014
@justinseanmartin
Copy link
Author

Credit for the fix goes to @wearhere. He cleaned up my quick and dirty fix and instead made the right fix. The new branch commit no longer should exhibit the issues that I called out as the potential issues.

NSUInteger lineStart = 0;
for (; charOffset < [charBuffer length] / sizeof(char); charOffset++) {
if (chars[charOffset] == '\n') {
NSData *lineData = [charBuffer subdataWithRange:NSMakeRange(lineStart, (charOffset - 1) * sizeof(char))];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I messed this up per Travis. I think it should be charOffset - 1 - lineStart?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up, running locally and on CI now, so far so good.

@wearhere
Copy link
Contributor

Thanks @justinseanmartin for exploring the edge cases here--and, I must note, suggesting the idea that I implemented, and then fixing my bug in that implementation. ;) Cheers.

wearhere added a commit that referenced this pull request Jul 10, 2014
…etter-utf8-decoding

Try and handle NSData UTF8 encoding failures in subliminal-instruments
@wearhere wearhere merged commit 47fdd89 into inkling:master Jul 10, 2014
@justinseanmartin justinseanmartin deleted the jmartin/SLInstruments-better-utf8-decoding branch July 10, 2014 05:50
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

Successfully merging this pull request may close these issues.

2 participants