Fix GDTCORFlatFileStorage crash #162
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix firebase/firebase-ios-sdk#14645
Gemini's analysis:
✦ I understand you're seeing a crash on iOS 18.3.2 related to directory enumeration in GDTCORFlatFileStorage. Based on the crash log you provided, the issue appears to stem from directory
creation (_mkpath, fstatat) within the storeEvent method, rather than enumeration. This could be due to a file system issue or a problem with how the storage path is being constructed or
accessed.
✦ After reviewing GDTCORFlatFileStorage.m, I've confirmed that the crash likely occurs within the storeEvent:onComplete: method. Specifically, the call to GDTCORWriteDataToFile seems to be
the source of the issue, as this is where the directory creation happens.
The stack trace indicates a failure in the underlying file system calls (_mkpath and fstatat) during directory creation. This could be due to a bug in iOS 18.3.2. A potential workaround
is to check if the directory exists before attempting to create it. This avoids unnecessarily calling createDirectoryAtPath if the directory is already present, which may prevent the
crash.
I've analyzed GDTCORPlatform.m and found that GDTCORWriteDataToFile is responsible for creating the directory before writing an event to a file. The current implementation directly
attempts to create the directory, which, as we've seen, can cause a crash on iOS 18.3.2.
To address this, I will modify GDTCORWriteDataToFile to first check if the directory already exists. If it does not, the code will then proceed to create it. This preventative check
should avoid the crash. I'll now apply this change.