Fix GDTCORDirectorySizeTracker crash #163
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#15414
Gemini's analysis:
This new stack trace points to a crash within GDTCORDirectorySizeTracker, specifically in the calculateDirectoryContentSize method. This is being called from GDTCORFlatFileStorage when a new event is stored. The crash seems to be related to memory allocation during directory enumeration, which could be caused by a number of factors, including a corrupted file system or an issue with how the directory enumeration is being performed.
After reviewing GDTCORDirectorySizeTracker.m, I see that the crash occurs in the calculateDirectoryContentSize method, which uses an NSDirectoryEnumerator to calculate the total size of all files in a given directory. The stack trace points to a crash deep within CoreFoundation's string creation and memory allocation functions, which suggests that the issue is likely caused by an underlying file system corruption or an unexpected file name that is causing the enumerator to fail.
The current implementation of the enumerator's errorHandler always returns YES, which tells the enumerator to continue even when an error has occurred. This can lead to unpredictable behavior and crashes if the underlying error is serious.
To fix this, I will modify the errorHandler to return NO when an error is encountered. This will stop the enumerator and prevent it from attempting to process any more files, which should prevent the crash. This change will make the directory size calculation more robust and prevent crashes caused by file system errors.