Skip to content

Fix remaining voice instructions out of bounds crash#2138

Merged
frederoni merged 3 commits into
masterfrom
fred/fix-spkn-index
May 29, 2019
Merged

Fix remaining voice instructions out of bounds crash#2138
frederoni merged 3 commits into
masterfrom
fred/fix-spkn-index

Conversation

@frederoni
Copy link
Copy Markdown
Contributor

This PR fixes an out of bounds array access crash in RouteStepProgress.getter:remainingVisualInstructions where RouteController.updateRouteLegProgress(status:) would access it at a point in time where the spoken instruction index hadn't been updated.

To keep the indexes in sync, all updating is now consolidated in RouteController.updateIndexes(status:) besides the leg index where the receiver of RouterDelegate.router(_:didArriveAt:) can determine if the index should be updated or not.

@mapbox/navigation-ios


if let instruction = currentStepProgress.currentVisualInstruction {
// Announce visual instruction if it was updated or it is the first location being reported
if didUpdate || isFirstLocation {
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.

If didUpdate is false, then is it safe to announce anything even if isFirstLocation is true?

Copy link
Copy Markdown
Contributor

@vincethecoder vincethecoder May 24, 2019

Choose a reason for hiding this comment

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

yep. This is a known anomaly in how data is received from directions. I wonder if this has been resolved.

Copy link
Copy Markdown
Contributor Author

@frederoni frederoni May 27, 2019

Choose a reason for hiding this comment

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

if isFirstLocation is true, that would mean stepIndex, visualInstructionIndex, and spokenInstructionIndex is 0. I can't think of a case where that wouldn't be safe, besides routeless navigation which currently is not supported. Also, there are no changes wrt to didUpdate and isFirst compared to before this PR which is reassuring.

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.

Ah, between the whitespace changes and variable renaming, I had mistakenly thought the logic had changed too. 👍

Incidentally, how well do we handle the pathological case of a route that ends at exactly or roughly the same spot as it begins, or a route with two coincident destinations? If I remember correctly, one of the features of OSRM is that it can give you a no-op route, unlike some other routing engines that make you go in a circle. Perhaps that edge case raises other issues that are out of scope for this PR, but that’s the only case that seems relevant to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

case of a route that ends at exactly or roughly the same spot as it begins, or a route with two coincident destinations?

Valid concerns but slightly out of scope for this PR.

I found one more place where indexes could be out of sync.

if advancesToNextLeg {
let legIndex = status.legIndex + 1
navigator.changeRouteLeg(forRoute: 0, leg: legIndex)
routeProgress.legIndex = Int(legIndex)
}

Fixed in bfe5ba7

?? DefaultBehavior.shouldRerouteFromLocation

updateRouteStepProgress(status: status)
updateIndexes(status: status)
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.

nit: plural of index is indices

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

both are valid pluralizations, indexes is even being used in Foundation, e.g. IndexPath.init(indexes:).

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.

That's fine. Realized it's accepted in American and Canadian English 😸

}

func updateSpokenInstructionProgress(status: MBNavigationStatus, willReRoute: Bool) {
func updateIndexes(status: MBNavigationStatus) {
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.

function signature suggestion:

func updateIndices(status: MBNavigationStatus) {
...
}

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.

nvm. it's an accepted spelling.

Copy link
Copy Markdown
Contributor

@JThramer JThramer 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 to me! :shipit:

@frederoni frederoni merged commit c5ee2ac into master May 29, 2019
@1ec5 1ec5 deleted the fred/fix-spkn-index branch December 5, 2019 18:25
@1ec5 1ec5 mentioned this pull request Jun 22, 2020
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