Opened 7 years ago

Closed 5 years ago

#11769 closed Bugs (fixed)

64-bit hash_combine has weakness against zero input

Reported by: Andrey Semashev Owned by: Daniel James
Milestone: To Be Determined Component: hash
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description (last modified by Andrey Semashev)

The hash_combine_impl function for 64-bit size_t (see here) does not have an additive component. As a result, hashing strings of zeros always results in zero hash value regardless of the length of the string.

Change History (3)

comment:1 by Andrey Semashev, 7 years ago

Description: modified (diff)

comment:2 by Daniel James, 7 years ago

Status: newassigned

You're right about the function but it turns out that there's no real problem for an embarrassing reason - that function has a spurious template argument so it's never used.

There are unit tests for this exact problem (in hash_sequence_test.hpp), and I'm relieved to say that they would have been caught the problem if that function was actually used, so at least I got that right.

I think I'll fix the function and put it to use. I had originally intended to do more rigorous testing of hash quality before releasing it, but ended up having little time. I think I'll be more cautious this time, so the new version might not make it into the next version of boost.

comment:3 by Daniel James, 5 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.