This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Copy features array before passing them to core #14804
Merged
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.
Closes #14565.
I have noticed, that the only possible scenario when the crash from #14565 can occur is when the collection is cleared while it's being converted to an array on our worker thread:
mapbox-gl-native/platform/android/src/geojson/feature_collection.cpp
Line 14 in 316584f
ArrayList#toArray
builds an array with a fixed size, adding anull
padding if necessary, therefore I think, that the collection has to be cleared on one thread, right when theArrayList#toArray
is copying the list on the other (after setting the resulting array's size and before finishing copying all of the elements, which creates thenull
padding).This is a race condition, so the only test I was able to come up with is a brute force. The test has been reliably reproducing the crash for me on every single run, either on a physical device or an emulator.
The solution is to copy the features array to a new array so that it cannot be modified by the provider. I was considering copying each
Feature
object as well, but it's not critical as modifying the feature should be safe and it introduced additional overhead.