Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Avoid unsafe cast when removing style layers - #7227

Merged
boundsj merged 1 commit into
release-ios-v3.4.0from
boundsj-fix-style-cast
Nov 30, 2016
Merged

boundsj merged 1 commit into
release-ios-v3.4.0from
boundsj-fix-style-cast

Conversation

@boundsj

@boundsj boundsj commented Nov 29, 2016 •

Copy link
Copy Markdown
Contributor

This updates the code generation for style layers to add a test to check that the style object returned from mbgl can be safely cast into the expected type so ownership can be returned to the caller when removing layers.

Previously a crash occurred if a layer of type T was added before a layer of type U but both layers shared the same identifier. In that case, if the pointer to the second layer of type U
was used to remove that layer, a runtime exception would occur since mbgl returns the layer with type T (the first one added) and the unsafe cast was triggered.

Now, even though the unsafe cast is avoided, an exception will still occur if layers with the same identifier are manipulated as described above but this is done as part of a validation check for all public style layer methods at the Darwin platform level. The raised NSException attempts to warn developers about reusing style identifiers to avoid this issue in the first place.

Fixes #7211

cc @1ec5 @jfirebaugh

@boundsj boundsj added crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling labels Nov 29, 2016
@boundsj boundsj added this to the ios-v3.4.0 milestone Nov 29, 2016
@boundsj boundsj self-assigned this Nov 29, 2016
@mention-bot

Copy link
Copy Markdown

@boundsj, thanks for your PR! By analyzing this pull request, we identified @1ec5 and @jfirebaugh to be potential reviewers.

of `MGLStyleLayer` and its subclasses. For private methods, an assertion is more appropriate.
*/
#define MGLAssertStyleLayerIsValid() \
do { \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please indent this macro so it’s more readable.

if (!self.rawLayer) { \
[NSException raise:@"Invalid style layer" \
format: \
@"-[%@ removeLayer:] has been called " \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The method is named -[MGLStyle removeLayer:], not -[MGL*StyleLayer removeLayer:].

This updates the code generation for style layers to add a test to check
that the style object returned from mbgl can be safely cast into the
expected type so ownership can be returned to the caller when removing
layers.

This scenario was previously possible if a layer of type T was
added before a layer of type U but both layers shared the same
identifier. In that case, if the pointer to the second layer of type U
was used to remove a layer, a runtime exception would occur since mbgl
returns the layer with type T (the first one added).

Now, an exception will still occur if layers with the same
identifier are manipulated as described above but it is done as part of
a validation check for all public style layer methods at the Darwin
platform level. The NSException attempts to warn developers about using
and reusing style identifiers to avoid this issue in the first place.
@boundsj
boundsj force-pushed the boundsj-fix-style-cast branch from 6d886b7 to 3e8f944 Compare November 30, 2016 17:16
@boundsj

boundsj commented Nov 30, 2016

Copy link
Copy Markdown
Contributor Author

Squashed and rebased on top of 0c518ad (#7128)

@boundsj
boundsj merged commit 37a087c into release-ios-v3.4.0 Nov 30, 2016
@boundsj
boundsj deleted the boundsj-fix-style-cast branch November 30, 2016 19:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants