From 025a958a20dab1d8433b5d8a74bcebd73af3eaa8 Mon Sep 17 00:00:00 2001 From: Tom Li Date: Thu, 3 Jan 2019 21:32:11 +0800 Subject: [PATCH] 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. Signed-off-by: Tom Li --- src/cube_hash.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cube_hash.h b/src/cube_hash.h index 9e4c0ee..c9df6ec 100644 --- a/src/cube_hash.h +++ b/src/cube_hash.h @@ -39,7 +39,11 @@ public: for (i = 0; i + B <= a.size(); i += B) state.process_block (& (a[i])); - state.process_final_incomplete_block (& (a[i]), a.size() - 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 result; result.resize (H, 0); state.get_hash (& (result[0]));