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

Ubsan findings fixes #1

Closed
wants to merge 5 commits into from

Conversation

SvetlanaBayarovich
Copy link
Owner

Issue

What issue is this PR targeting? If there is no issue that addresses the problem, please open a corresponding issue and link it here.

Resolves findings of the Undefined behavior sanitizer.

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Generally use squash merge to rebase and clean comments before merging
  • Update the changelog

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

It is currently rebased on my sanitizer-support branch in order to show only relevant diff but include ubsan flags as well. To be rebased on the main branch later

@@ -503,7 +503,7 @@ void DirectedEdge::set_superseded(const uint32_t superseded) {
if (superseded > kMaxShortcutsFromNode) {
LOG_WARN("Exceeding max shortcut edges from a node: " + std::to_string(superseded));
} else {
superseded_ = (1 << (superseded - 1));
superseded_ = superseded ? (1 << (superseded - 1)) : 0;
Copy link
Owner Author

Choose a reason for hiding this comment

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

shift exponent 4294967295 is too large error here if superseded is zero

// Make sure everything is 64 bit!
uint64_t shift = localidx * 8; // 8 bits per index
return static_cast<uint32_t>(std::round(
((headings_ & (static_cast<uint64_t>(255) << shift)) >> shift) * kHeadingExpandFactor));
Copy link
Owner Author

Choose a reason for hiding this comment

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

Also a problem with shift exponent. At set function too big localidx is skipped (see the line).
I added the same check but I'm not 100% sure what the return should be.

Choose a reason for hiding this comment

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

related. valhalla#2494

Why would we be calling this with a high index?

Choose a reason for hiding this comment

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

can only store headings for 8 local indexes and the if statement protects if localindex > 7. The node based headings probably need to be deprecated. These headings are only used in map matching (could use simplified turn costing logic) and during data creation (can create temporary sequence files to look up headings to all edges).

@@ -631,7 +631,7 @@ void GraphValidator::Validate(const boost::property_tree::ptree& pt) {
}
sum += density;
}
float average_density = sum / densities[level].size();
float average_density = densities[level].size() ? sum / densities[level].size() : 0.f;
Copy link
Owner Author

@SvetlanaBayarovich SvetlanaBayarovich Jul 23, 2020

Choose a reason for hiding this comment

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

For astar test only for level 2 densities[level].size() is non-zero. Can it be because of test map is not "realistic" or this is an expected result for some input data (e.g. small)?

@@ -61,7 +61,7 @@ struct TrafficSpeeds {
};

// Convert big endian bytes to little endian
int16_t to_little_endian(const int16_t val) {
int16_t to_little_endian(const uint16_t val) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

To get rid of left shift in case of negative value. It also seems more logical if we treat the bytes to be swapped as something unsigned. It also helps to get rid of right shift of negative value which is implementation-defined (not UB but still...)

@SvetlanaBayarovich SvetlanaBayarovich force-pushed the sanitizer-checks branch 10 times, most recently from 0d8bd68 to 671cd24 Compare July 24, 2020 18:18
@purew
Copy link

purew commented Jul 29, 2020

I measured no difference between 0f41d17 and master when running 23886 routes.

@SvetlanaBayarovich SvetlanaBayarovich force-pushed the sanitizer-checks branch 2 times, most recently from 91764ae to 55c18ae Compare July 31, 2020 14:11
@SvetlanaBayarovich
Copy link
Owner Author

Work moved to valhalla#2498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants