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

Potential integer underflow in file suffix generation #3783

Merged

Conversation

PhilippVoigt
Copy link
Contributor

fixes #3780

For certain level configurations the maximum tile ID can be a 6-digit number, e.g. for 512-by-265 tiles. In this case the separator at index 0 is added to the file suffix and the unsigned variable ind is reduced by 1 leading to a large positive number which causes an out-of-bounds in the subsequent loop. The default level configuration does not lead to 6-digit tile IDs, therefore the changes were tested solely for our own use cases, which might differ from yours.

Philipp Voigt (philipp.voigt@mercedes-benz.com) on behalf of Mercedes-Benz Tech Innovation GmbH.
Provider Information

Licensed under MIT

Integer underflow if maximum tile ID for leven is a 6-digit number.

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
@PhilippVoigt PhilippVoigt changed the title Potential integer upderflow in file suffix generation Potential integer underflow in file suffix generation Oct 6, 2022
Added CHANGELOG.md entry

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
Added CHANGELOG.md entry

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
nilsnolde
nilsnolde previously approved these changes Oct 6, 2022
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

LGTM thanks. Only changelog fix left: order is chronologically descending, so newest comes last in the list.

Moved CHANGELOG.md entry down

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
@PhilippVoigt
Copy link
Contributor Author

Only changelog fix left: order is chronologically descending, so newest comes last in the list.

Sorry, beginner's mistake. Thanks for reviewing this so quickly!

@nilsnolde
Copy link
Member

Sorry, beginner's mistake.

No worries, it's not very intuitive, literally every first time contributor to Valhalla does that (which would speak for a PR template overhaul..)

@nilsnolde nilsnolde self-requested a review October 6, 2022 07:52
nilsnolde
nilsnolde previously approved these changes Oct 6, 2022
@kevinkreiser
Copy link
Member

this is too perfect a test case to not actually add a test for it. i'm going to do so. perhaps we can also simplify the code a bit.

@PhilippVoigt
Copy link
Contributor Author

this is too perfect a test case to not actually add a test for it. i'm going to do so. perhaps we can also simplify the code a bit.

I actually spent some time trying to add a test case but there is no way to reproduce it with the constants returned by TileHierarchy::levels(). I wasn't too sure how this can be mocked for a test.

@kevinkreiser
Copy link
Member

Yeah its quite annoying because of the static use of tileheirarchy. I was able to do it locally though. i'll push an update to your branch with it after i confirm it fails on master

@kevinkreiser
Copy link
Member

@PhilippVoigt i added a test here but i found that even master successfully passed the test! would you be able to tweak the test to actually test for the case that your code fixes?

Added test case with GraphId that uses all 6 available digits

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
@PhilippVoigt
Copy link
Contributor Author

@PhilippVoigt i added a test here but i found that even master successfully passed the test! would you be able to tweak the test to actually test for the case that your code fixes?

The problematic TileIDs are those that fill all 6 available digits, so with TileID 123456, we can make it fail on master. I added an ASSERT_EXIT to make sure the test actually fails since it otherwise gets interrupted by SIGSEGV and doesn't report it's outcome. Is that fine for you or are there better ways to catch SIGSEGV?

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

Pretty much done now. Only remove that one test line and you need to

  • merge master after you
  • run pre-commit: just do a ./script/format.sh, that'll install pre-commit and run format.sh which will fix the formatting

TileLevel level{7, valhalla::baldr::RoadClass::kSecondary, "half_degree_is_a_multiple_of_3",
Tiles<PointLL>{{{-180, -90}, {180, 90}}, .5, 1}};
EXPECT_EQ(GraphTile::FileSuffix(GraphId(1234, 7, 0), ".qux", false, &level), "7/001/234.qux");
ASSERT_EXIT((GraphTile::FileSuffix(GraphId(123456, 7, 0), ".qux", false, &level),exit(0)),::testing::ExitedWithCode(0),".*");
Copy link
Member

@nilsnolde nilsnolde Oct 10, 2022

Choose a reason for hiding this comment

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

You can remove the ASSERT_EXIT I guess. The point was that the below test line should fail master, we can't verify that anymore on this branch since you fixed it. It's enough for us when you say "jep, the below test fails master". Just verified it myself, you can safely remove this test line.

Confirmed that test fails on master and removed assert

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
Confirmed that test fails on master and removed assert

Signed-off-by: Philipp Voigt (<philipp.voigt@mercedes-benz.com>)
nilsnolde
nilsnolde previously approved these changes Oct 10, 2022
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

Thanks @PhilippVoigt LGTM. I’ll let Kevin merge.

@PhilippVoigt
Copy link
Contributor Author

@kevinkreiser Is there a chance we could merge this in time for release 3.2.0? We currently depend on this fix and it would help us to base our work on a specific release. Thanks!

@nilsnolde
Copy link
Member

Yeah we’re just having 2 weekly merge PR meetings. We go chronologically more or less. We won’t release before all the low hanging fruits like this PR aren’t merged, no worries:) I’ll add this one later to the list in the release issue

kevinkreiser
kevinkreiser previously approved these changes Oct 23, 2022
@nilsnolde nilsnolde dismissed stale reviews from kevinkreiser and themself via 00bcef6 October 23, 2022 15:40
@nilsnolde nilsnolde merged commit 9137c5d into valhalla:master Oct 23, 2022
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.

Unsigned integer underflow in graphtile.cc
3 participants