aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-13 12:46:33 +0100
committerStefan Boberg <[email protected]>2024-12-13 12:46:33 +0100
commitd3acaeed37a316f4e3e5b98594cb76ad1de70af2 (patch)
treeeaf224c523c7942a898cd78319a789a9b4c4ac52 /src
parentadded test verification of XXH3_128Stream vs XXH3_128::HashMemory (diff)
downloadzen-d3acaeed37a316f4e3e5b98594cb76ad1de70af2.tar.xz
zen-d3acaeed37a316f4e3e5b98594cb76ad1de70af2.zip
Implemented temporary workaround for long paths in ComputeOpKey
also added a test case to exercise the logic
Diffstat (limited to 'src')
-rw-r--r--src/zenserver/projectstore/projectstore.cpp75
1 files changed, 72 insertions, 3 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp
index 1257ac8a8..ef2c2e4ab 100644
--- a/src/zenserver/projectstore/projectstore.cpp
+++ b/src/zenserver/projectstore/projectstore.cpp
@@ -412,9 +412,27 @@ ComputeOpKey(const CbObjectView& Op)
{
using namespace std::literals;
- XXH3_128Stream_deprecated KeyHasher;
- Op["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
- XXH3_128 KeyHash128 = KeyHasher.GetHash();
+ BinaryWriter KeyStream;
+
+ Op["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyStream.Write(Data, Size); });
+
+ XXH3_128 KeyHash128;
+
+ // This logic currently exists to work around a problem caused by misusing the xxhash
+ // functions in the past. Short keys are evaluated using the old and buggy
+ // path but longer paths are evaluated properly. In the future all key lengths
+ // should be evaluated using the proper path, this is a temporary workaround to
+ // maintain compatibility with existing disk state.
+ if (KeyStream.GetSize() < 240)
+ {
+ XXH3_128Stream_deprecated KeyHasher;
+ KeyHasher.Append(KeyStream.Data(), KeyStream.Size());
+ KeyHash128 = KeyHasher.GetHash();
+ }
+ else
+ {
+ KeyHash128 = XXH3_128::HashMemory(KeyStream.GetView());
+ }
Oid KeyHash;
memcpy(&KeyHash, KeyHash128.Hash, sizeof KeyHash);
@@ -6707,6 +6725,57 @@ namespace testutils {
} // namespace testutils
+TEST_CASE("project.opkeys")
+{
+ using namespace std::literals;
+
+ const std::string_view LongKey =
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"sv;
+
+ // Not a test per se, this code just exercises the key computation logic to ensure all
+ // edge cases are handled by the bug workaround logic
+
+ for (int i = 1; i < 300; ++i)
+ {
+ CbObjectWriter Cbo;
+ Cbo << "key"sv << LongKey.substr(0, i);
+
+ const Oid KeyId = ComputeOpKey(Cbo.Save());
+ }
+
+ {
+ CbObjectWriter Cbo;
+ Cbo << "key"sv
+ << "abcdef";
+
+ const Oid KeyId = ComputeOpKey(Cbo.Save());
+ const Oid CorrectId = Oid::FromHexString(
+ "7a03540e"
+ "ecb0daa9"
+ "00f2949e");
+
+ CHECK(KeyId == CorrectId);
+ }
+
+ {
+ CbObjectWriter Cbo;
+ Cbo << "key"sv
+ << "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
+
+ const Oid KeyId = ComputeOpKey(Cbo.Save());
+ const Oid CorrectId = Oid::FromHexString(
+ "c5e88c79"
+ "06b7fa38"
+ "7b0d2efd");
+
+ CHECK(KeyId == CorrectId);
+ }
+}
+
TEST_CASE("project.store.create")
{
using namespace std::literals;