Skip to content

Conversation

JesusRojass
Copy link
Contributor

Prevent possible crashes adressing comments from #15317 and crash reported in #14734

Discussion

This addresses the comments for the proposed improvements not addressing the possible crash found when MIMEType is called by adding a little try catch and keeping the improvements made in the past pull request

@ncooke3 Hoping this is better!

Testing

  • Ran repeatedly 1000 Unit tests locally in XCode to check for flakiness with and without network link conditioner on a: iPhone 14 Pro running iOS 18.6.2 and an iPhone SE 3rd Gen Simulator on iOS 18.6.2
  • Code Altered shouldn't edit functionality it's just an extra safety step

API Changes

No API Changes

Prevent possible crashes
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@JesusRojass
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a @try-@catch block to defensively access the MIMEType property of an NSURLResponse, preventing a potential crash. The change is straightforward and addresses the reported issue. I've added one suggestion to improve the implementation by logging the caught exception for better diagnostics, while also removing a redundant line of code.

JesusRojass and others added 2 commits September 11, 2025 11:10
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment on lines +254 to +264
// Defensive access to MIMEType
NSString *mime = nil;
@try {
// Safely copy MIMEType to prevent use after free
mime = [response.MIMEType copy];
} @catch (NSException *exception) {
FPRLogWarning(@"MIMETypeException",
@"Exception while accessing MIMEType for URL %@: %@. Trace will continue "
@"without MIMEType.",
self.URLRequest.URL, exception);
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe a crash like this can be handled. Only NSExceptions can be handled and there isn't one being raised here. This crash is coming at a lower level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would wrapping the 2 lines I already contributed in a if (response) for example would be a better solution? (of course keeping tabs if the crash ever shows up again)

Copy link
Member

Choose a reason for hiding this comment

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

No, because in order for the getMIMEType method to appear in the stack trace, the response is non-nil. Because if the response was nil, the MIMEType call would be a no-op.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok got it, I'm a bit out of ideas maybe I can do a bit more research and try a better solution for this

Thanks Nick

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