From a26427392f5341af810d5117e242b18b5223666f Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 2 Nov 2019 06:14:38 -0700 Subject: [PATCH] Made string hashing more robust We need to ensure that mixing in "AB" and then "C" is distinct from "A" and then "BC" - so we mix in the length ahead --- BeefySysLib/util/Hash.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/BeefySysLib/util/Hash.cpp b/BeefySysLib/util/Hash.cpp index a003325d..c5b97293 100644 --- a/BeefySysLib/util/Hash.cpp +++ b/BeefySysLib/util/Hash.cpp @@ -1406,17 +1406,22 @@ void HashContext::Mixin(const void* data, int size) void HashContext::MixinHashContext(HashContext& ctx) { + Mixin(ctx.mBufSize); Mixin(ctx.mBuf, ctx.mBufSize); } void HashContext::MixinStr(const char* str) { - Mixin(str, (int)strlen(str)); + int len = (int)strlen(str); + Mixin(len); + Mixin(str, len); } void HashContext::MixinStr(const StringImpl& str) { - Mixin(str.c_str(), (int)str.length()); + int len = (int)str.length(); + Mixin(len); + Mixin(str.c_str(), len); } Val128 HashContext::Finish128()