From 436c882119a3c8133f03c829fc1bdffcda4d6a0a Mon Sep 17 00:00:00 2001 From: fixxxedpoint <42604451+fixxxedpoint@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:54:41 +0100 Subject: [PATCH 1/3] FIX: off-by-one error when identifying the patch/Rack version by reading the magic sequence of a zstd-compressed patch. --- src/CardinalPlugin.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index dfe19a7..a1db4a9 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -28,6 +28,7 @@ #endif #include +#include #include #include "CardinalCommon.hpp" @@ -1104,9 +1105,10 @@ protected: rack::system::removeRecursively(fAutosavePath); rack::system::createDirectories(fAutosavePath); - static constexpr const char zstdMagic[] = "\x28\xb5\x2f\xfd"; + static constexpr const std::size_t zstdMagicSize = 4 + static constexpr const char zstdMagic[zstdMagicSize + 1] = "\x28\xb5\x2f\xfd"; - if (std::memcmp(data.data(), zstdMagic, sizeof(zstdMagic)) != 0) + if (std::memcmp(data.data(), zstdMagic, zstdMagicSize) != 0) { FILE* const f = std::fopen(rack::system::join(fAutosavePath, "patch.json").c_str(), "w"); DISTRHO_SAFE_ASSERT_RETURN(f != nullptr,); From 4aa6d614b34617c293f7760f4dd2dd5b57ca51c7 Mon Sep 17 00:00:00 2001 From: fixxxedpoint <42604451+fixxxedpoint@users.noreply.github.com> Date: Wed, 26 Nov 2025 21:07:04 +0100 Subject: [PATCH 2/3] review: using array of uint8_t instead of char[] for recognizing magic number of an zstd archive --- src/CardinalPlugin.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index a1db4a9..eab38c3 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -28,7 +28,6 @@ #endif #include -#include #include #include "CardinalCommon.hpp" @@ -1105,10 +1104,9 @@ protected: rack::system::removeRecursively(fAutosavePath); rack::system::createDirectories(fAutosavePath); - static constexpr const std::size_t zstdMagicSize = 4 - static constexpr const char zstdMagic[zstdMagicSize + 1] = "\x28\xb5\x2f\xfd"; + static constexpr const uint8_t zstdMagic[] = { 0x28, 0xb5, 0x2f, 0xfd }; - if (std::memcmp(data.data(), zstdMagic, zstdMagicSize) != 0) + if (std::memcmp(data.data(), zstdMagic, sizeof(zstdMagic)) != 0) { FILE* const f = std::fopen(rack::system::join(fAutosavePath, "patch.json").c_str(), "w"); DISTRHO_SAFE_ASSERT_RETURN(f != nullptr,); From 8f922a841799ed337586aa56ca8aa83c71140ef4 Mon Sep 17 00:00:00 2001 From: fixxxedpoint <42604451+fixxxedpoint@users.noreply.github.com> Date: Wed, 26 Nov 2025 21:27:49 +0100 Subject: [PATCH 3/3] review: explicit size of the zstd magic number array --- src/CardinalPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CardinalPlugin.cpp b/src/CardinalPlugin.cpp index eab38c3..65ab9a6 100644 --- a/src/CardinalPlugin.cpp +++ b/src/CardinalPlugin.cpp @@ -1104,7 +1104,7 @@ protected: rack::system::removeRecursively(fAutosavePath); rack::system::createDirectories(fAutosavePath); - static constexpr const uint8_t zstdMagic[] = { 0x28, 0xb5, 0x2f, 0xfd }; + static constexpr const uint8_t zstdMagic[4] = { 0x28, 0xb5, 0x2f, 0xfd }; if (std::memcmp(data.data(), zstdMagic, sizeof(zstdMagic)) != 0) {