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: Crash when Getting Subclasses #1396

Merged
merged 3 commits into from
Oct 18, 2021
Merged

Conversation

philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Oct 15, 2021

📜 Description

Calling class_getSuperclass sometimes leads to EXC_I386_GPFLT. OneSignal
had the same issue OneSignal/OneSignal-iOS-SDK#278
and it was fixed with OneSignal/OneSignal-iOS-SDK#301.
This PR applies the changes they did to our code to fix the problem.

💡 Motivation and Context

Fixes GH-1395

💚 How did you test it?

Waiting for validation in GH-1395

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

Calling class_getSuperclass sometimes leads to EXC_I386_GPFLT. OneSignal
had the same issue OneSignal/OneSignal-iOS-SDK#278
and it was fixed with OneSignal/OneSignal-iOS-SDK#301.
This PR applies the changes they did to our code to fix the problem.

Fixes GH-1395
Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

code lgtm, just not quite sure about the logic

superClass = class_getSuperclass(superClass);
} while (superClass && superClass != parentClass);
}

if (superClass != nil) {
Copy link
Member

Choose a reason for hiding this comment

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

I’m wondering when/if this condition can ever be reached?
According to the while loop above, superClass either needs to be nil or equal to parentClass to go over that. And above, you explicitly excluded the parentClass case, so I’m unsure what the code is supposed to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

The parentClass was excluded before the loop. But using class_getSuperclass we can get the parentClass again

Copy link
Member Author

@philipphofmann philipphofmann Oct 18, 2021

Choose a reason for hiding this comment

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

Good point @Swatinem. class_getSuperclass returns nil if the passed in class is a root class, like NSObject. Therefore, we need this check.

Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

Just wondering, what if we do the class image check here in the background minimizing the amount of classes in the indexesToSwizzle reducing code to run in the main thread later.

@philipphofmann
Copy link
Member Author

Just wondering, what if we do the class image check here in the background minimizing the amount of classes in the indexesToSwizzle reducing code to run in the main thread later.

I'm not sure if I follow you here @brustolin. We do everything on a background thread except the swizzling.

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2021

Codecov Report

Merging #1396 (9d71b24) into master (e3ae241) will decrease coverage by 0.19%.
The diff coverage is 56.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1396      +/-   ##
==========================================
- Coverage   96.05%   95.86%   -0.20%     
==========================================
  Files         152      152              
  Lines        6747     6764      +17     
==========================================
+ Hits         6481     6484       +3     
- Misses        266      280      +14     
Impacted Files Coverage Δ
Sources/Sentry/SentryUIViewControllerSwizziling.m 75.82% <56.52%> (-2.36%) ⬇️
Sources/Sentry/SentryRequestOperation.m 69.23% <0.00%> (-12.83%) ⬇️
Sources/Sentry/SentryInstallation.m 86.95% <0.00%> (-8.70%) ⬇️
Sources/Sentry/SentryNetworkTracker.m 99.41% <0.00%> (+0.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3ae241...9d71b24. Read the comment docs.

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

Successfully merging this pull request may close these issues.

7.4.5 Crash on launch
4 participants