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

[PLAT-6973] Fix stack overflow in +[BugsnagThread allThreadsWithCurrentThreadBacktrace:] #1148

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

nickdowell
Copy link
Contributor

@nickdowell nickdowell commented Jul 7, 2021

Goal

Fix a crash due to a stack overflow when recording thread backtraces in an app that has lots (~500+) threads.

Exception Type:     EXC_BAD_ACCESS 
Exception Subtype:  KERN_PROTECTION_FAILURE

EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0x171e083b8.

0  AppName    bsg_ksbt_backtraceThreadState (BSG_KSBacktrace.c:145:28)
1  AppName    backtrace_for_thread (BugsnagThread.m:47:38)
2  AppName    +[BugsnagThread allThreadsWithCurrentThreadBacktrace:] (BugsnagThread.m:235:13)
3  AppName    +[BugsnagThread allThreads:callStackReturnAddresses:] (BugsnagThread.m:207:16)

This crash is less likely to occur on the main thread because it has a larger default stack size than background threads.

Changeset

Memory for the backtraces is now allocated from the heap rather than the stack.

Testing

Reproduced the crash in a unit test, verified it now passes.

@github-actions
Copy link

github-actions bot commented Jul 7, 2021

Infer: No issues found 🎉

OCLint: No issues found 🎉

Bugsnag.framework binary size did not change - 1,134,024 bytes

Generated by 🚫 Danger

@nickdowell nickdowell merged commit 7545d35 into next Jul 7, 2021
@nickdowell nickdowell deleted the nickdowell/fix-threads-stack-overflow branch July 7, 2021 09:20
@nickdowell nickdowell mentioned this pull request Jul 7, 2021
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