cube_hash.h: finalize CubeHash if there's no incomplete block.
Previously, we assume the existence of a incomplete block at
end of the input. However, it's possible that input's an exact
multiple of block size. In this case, the first argument of
process_final_incomplete_block() will be one-past-the-last
element, the second argument will be zero. This' an ill-defined
call, and it will trigger an assertion failure of std::vector
Assertion '__builtin_expect(__n < this->size(), true)' failed.
This commit introduced a check. If we see the length of the last
incomplete block is zero, we call
process_final_incomplete_block(NULL, 0);
which immediately finalizes CubeHash without hashing additional
data.
Although it should be changed to
state.process_final_incomplete_block (a.data() + a.size(),
a.size() - i);
It hides the possibility of passing an out-of-bound element to
the function, so it's better to be explicit.
Signed-off-by: Tom Li <tomli@tomli.me>
This commit is contained in:
parent
7021f6c734
commit
6e53922328
|
|
@ -39,7 +39,11 @@ public:
|
|||
for (i = 0; i + B <= a.size(); i += B)
|
||||
state.process_block (& (a[i]));
|
||||
|
||||
if (a.size() - i != 0)
|
||||
state.process_final_incomplete_block (& (a[i]), a.size() - i);
|
||||
else
|
||||
state.process_final_incomplete_block (NULL, 0); //empty block, just finalize
|
||||
|
||||
std::vector<byte> result;
|
||||
result.resize (H, 0);
|
||||
state.get_hash (& (result[0]));
|
||||
|
|
|
|||
Loading…
Reference in a new issue