Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate duplicate stops in stylesheets. #4498

Closed
wants to merge 1 commit into from

Conversation

vicapow
Copy link
Contributor

@vicapow vicapow commented Mar 27, 2017

Otherwise, duplicate pairs for a stop in a style can cause binarySearchForIndex() to enter an infinite loop. This didn't immediately cause issues because of an earlier bug in mapbox-gl-function that was introduced between 0.32.1 and 0.33 as part of this rebase with the mapbox-gl-function library.

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

Looks good apart from the nitpick!

}
seenStops[stop[0]] = stop[1];
return true;
});
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't actually use the returned value of every, it makes more sense to use a for ... of loop here.

@mourner
Copy link
Member

mourner commented Mar 27, 2017

Also, what's the earlier bug you mentioned and should it be reported as well?

@jfirebaugh
Copy link
Contributor

See discussion on #4107 and mapbox/mapbox-gl-style-spec#411: we tried adding this validation, but reverted it when it became clear that styles with duplicate stops were somewhat widespread and it would be difficult to migrate them without incrementing the style spec version number. Do we want to revisit that decision?

@mourner
Copy link
Member

mourner commented Mar 27, 2017

On a second thought, we should probably fix the infinite loop problem in the binary search implementation rather then avoiding the situation with validation then. cc @kronick

@vicapow
Copy link
Contributor Author

vicapow commented Mar 27, 2017

Also, what's the earlier bug you mentioned and should it be reported as well?

Prior to mapbox/mapbox-gl-function#35, duplicate stops wouldn't trigger the infinite loop in my styles. It landed in mapbox-gl-js as part of this merge. Specifically:

-    "mapbox-gl-function": "mapbox/mapbox-gl-function#41c6724e2bbd7bd1eb5991451bbf118b7d02b525",
+    "mapbox-gl-function": "mapbox/mapbox-gl-function#4f829622413f336080d3c710244c251421c0ec30",

Just to confirm, should binarySearchForIndex() be updated to only pick the first stop when there's duplicates?

@lucaswoj
Copy link
Contributor

See discussion on #4107 and mapbox/mapbox-gl-style-spec#411: we tried adding this validation, but reverted it when it became clear that styles with duplicate stops were somewhat widespread and it would be difficult to migrate them without incrementing the style spec version number. Do we want to revisit that decision?

This seems like a change that'd need to wait for a semver major version bump. There are several other validation strict-ening changes we'd probably want to make at once. (i.e. disallowing arbitrary properties on the style root object)

@vicapow
Copy link
Contributor Author

vicapow commented Mar 27, 2017

I agree. It should fix this problem in the short term if we change binarySearchForIndex to not enter an infinite loop when there are duplicate keys.

A newer version of the spec can enforce the prevention of duplicate keys.

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.

4 participants