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

Fix a rare crash caused by an unchecked return value. #255

Conversation

ewanmellor
Copy link
Contributor

Fix a rare crash in CompressingLogFileManager caused by an
unchecked result from read. If the read fails, it returns -1.
This was then added to inputDataSize, which in turn is added to
inputRemaining further down the function, and used as an input
to memmove (and is unsigned to boot, so it'll be very large rather than
negative). This means that the memmove stomps all over memory,
and we crash not long afterwards (often when an autorelease pool is
freed).

This crash is rare because it depends on the read call failing.

Fix this by checking the return value from NSStream.read, and leaving
the loop immediately if there's an error.

Ewan Mellor added 2 commits March 31, 2014 18:37
Log the streamError whenever we fail to write during compression,
and log any failures when removing the original file or cleaning up
the temporary file after compression failed.
Fix a rare crash in CompressingLogFileManager caused by an
unchecked result from read.  If the read fails, it returns -1.
This was then added to inputDataSize, which in turn is added to
inputRemaining further down the function, and used as an input
to memmove (and is unsigned to boot, so it'll be very large rather than
negative).  This means that the memmove stomps all over memory,
and we crash not long afterwards (often when an autorelease pool is
freed).

This crash is rare because it depends on the read call failing.

Fix this by checking the return value from NSStream.read, and leaving
the loop immediately if there's an error.
@ewanmellor
Copy link
Contributor Author

The first cset here is PR #250, so this PR is dependent on that one.

(I'm sure GitHub used to be able to handle dependencies between PRs, but I can't find that option now).

if (readLength < 0) {
error = [inputStream streamError];
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

So the addition to the mentioned pull request is this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. Commit 44da95a.

bpoplauschi added a commit that referenced this pull request Apr 1, 2014
…ead-return

Fix a rare crash caused by an unchecked return value.
@bpoplauschi bpoplauschi merged commit f31fce5 into CocoaLumberjack:master Apr 1, 2014
@bpoplauschi
Copy link
Member

Thanks @ewanmellor

@ewanmellor ewanmellor deleted the CompressingLogFileManager-check-read-return branch April 1, 2014 07:42
@bpoplauschi bpoplauschi added this to the 1.9.0 milestone May 16, 2014
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.

3 participants