From 7edce967f29732fa3aa68b26fcadad75c06dff78 Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 29 Jul 2026 00:41:57 +0300 Subject: [PATCH] Update: align component feed identities --- include/Void/Update/Feed.hpp | 7 ++- src/Update/Feed.cpp | 81 +++++++++++++++++++++++++++--- tests/standalone/Update/Update.cpp | 23 +++++++-- 3 files changed, 100 insertions(+), 11 deletions(-) diff --git a/include/Void/Update/Feed.hpp b/include/Void/Update/Feed.hpp index d7ce932..6016714 100644 --- a/include/Void/Update/Feed.hpp +++ b/include/Void/Update/Feed.hpp @@ -100,6 +100,7 @@ namespace Void::Update std::string kind; Semver::Version componentVersion; std::string activation; + std::map dependencyConstraints; std::map dependencies; std::uint64_t sequence{0}; std::string latestUrl; @@ -129,9 +130,13 @@ namespace Void::Update Semver::Version componentVersion; std::string sourceSha; std::string sourceTreeHash; - std::string abiHash; + std::optional abiHash; std::string artifactIdentity; std::string activation; + std::string platform; + std::string architecture; + std::string toolchainContract; + std::map dependencyConstraints; std::map dependencies; ComponentArtifact artifact; }; diff --git a/src/Update/Feed.cpp b/src/Update/Feed.cpp index dd7bdc1..39b6042 100644 --- a/src/Update/Feed.cpp +++ b/src/Update/Feed.cpp @@ -101,6 +101,21 @@ namespace Void::Update }); } + [[nodiscard]] bool + valid_prefixed_hash(std::string_view value, std::string_view prefix, + std::size_t hexadecimalSize) noexcept + { + if (!value.starts_with(prefix)) { + return false; + } + const auto hexadecimal = value.substr(prefix.size()); + return hexadecimal.size() == hexadecimalSize && + std::ranges::all_of(hexadecimal, [](const char character) { + return (character >= '0' && character <= '9') || + (character >= 'a' && character <= 'f'); + }); + } + [[nodiscard]] bool valid_hex(std::string_view value, std::size_t size) noexcept { @@ -395,6 +410,20 @@ namespace Void::Update return std::optional{value->as_string()}; } + [[nodiscard]] Void::Result::Result> + optional_string(const Json::Value& object, std::string_view name) + { + const auto* value = object.find(name); + if (value == nullptr || value->is_null()) { + return std::optional{}; + } + if (!value->is_string()) { + return Void::Result::fail(std::format( + "Component feed: {} must be null or a string", name)); + } + return std::optional{value->as_string()}; + } + [[nodiscard]] Void::Result::Result< std::map> parse_dependencies(const Json::Value& object) @@ -421,6 +450,27 @@ namespace Void::Update return result; } + [[nodiscard]] Void::Result::Result> + parse_dependency_constraints(const Json::Value& object) + { + const auto* dependencies = object.find("dependencies"); + if (dependencies == nullptr || !dependencies->is_object()) { + return Void::Result::fail( + "Component feed: dependencies must be an object"); + } + std::map result; + for (const auto& [component, value] : dependencies->as_object()) { + if (!valid_token(component, 256) || !value.is_string() || + value.as_string().empty() || + value.as_string().size() > 512) { + return Void::Result::fail( + "Component feed: dependency contains an unsafe field"); + } + result.emplace(component, value.as_string()); + } + return result; + } + [[nodiscard]] Void::Result::Result parse_component_header(const Json::Value& document, std::string_view expectedDocument, @@ -490,12 +540,14 @@ namespace Void::Update auto sequence = unsigned_number(value, "sequence"); auto latestUrl = string_member(value, "latestUrl"); auto artifactSha = string_member(value, "artifactSha256"); + auto dependencyConstraints = parse_dependency_constraints(value); auto dependencies = parse_dependencies(value); if (!componentId || !pluginId || !kind || !versionText || !activation || !sequence || !latestUrl || !artifactSha || - !dependencies || !valid_token(*componentId, 256) || - !valid_token(*kind, 128) || !valid_token(*activation, 128) || - !bounded_url(*latestUrl) || !valid_sha256(*artifactSha)) { + !dependencyConstraints || !dependencies || + !valid_token(*componentId, 256) || !valid_token(*kind, 128) || + !valid_token(*activation, 128) || !bounded_url(*latestUrl) || + !valid_sha256(*artifactSha)) { return Void::Result::fail( "Component feed: catalog entry contains an unsafe field"); } @@ -510,6 +562,7 @@ namespace Void::Update .kind = std::move(*kind), .componentVersion = std::move(*version), .activation = std::move(*activation), + .dependencyConstraints = std::move(*dependencyConstraints), .dependencies = std::move(*dependencies), .sequence = *sequence, .latestUrl = std::move(*latestUrl), @@ -690,19 +743,28 @@ namespace Void::Update auto componentVersion = string_member(*document, "componentVersion"); auto sourceSha = string_member(*document, "sourceSha"); auto sourceTreeHash = string_member(*document, "sourceTreeHash"); - auto abiHash = string_member(*document, "abiHash"); + auto abiHash = optional_string(*document, "abiHash"); auto artifactIdentity = string_member(*document, "artifactIdentity"); auto activation = string_member(*document, "activation"); + auto platform = string_member(*document, "platform"); + auto architecture = string_member(*document, "architecture"); + auto toolchainContract = string_member(*document, "toolchainContract"); + auto dependencyConstraints = parse_dependency_constraints(*document); auto dependencies = parse_dependencies(*document); const auto* artifactValue = document->find("artifact"); if (!header || !componentId || !pluginId || !kind || !componentVersion || !sourceSha || !sourceTreeHash || !abiHash || - !artifactIdentity || !activation || !dependencies || + !artifactIdentity || !activation || !platform || !architecture || + !toolchainContract || !dependencyConstraints || !dependencies || artifactValue == nullptr || !artifactValue->is_object() || !valid_token(*componentId, 256) || !valid_token(*kind, 128) || !valid_token(*artifactIdentity, 256) || - !valid_token(*activation, 128) || !valid_hex(*sourceSha, 40) || - !valid_sha256(*sourceTreeHash) || !valid_sha256(*abiHash)) { + !valid_token(*activation, 128) || !valid_token(*platform, 64) || + !valid_token(*architecture, 64) || + !valid_token(*toolchainContract, 256) || + !valid_hex(*sourceSha, 40) || + !valid_prefixed_hash(*sourceTreeHash, "git-sha1:", 40) || + (*abiHash && !valid_prefixed_hash(**abiHash, "sha256:", 64))) { return Void::Result::fail( "Component feed: release contains an unsafe field"); } @@ -737,6 +799,10 @@ namespace Void::Update .abiHash = std::move(*abiHash), .artifactIdentity = std::move(*artifactIdentity), .activation = std::move(*activation), + .platform = std::move(*platform), + .architecture = std::move(*architecture), + .toolchainContract = std::move(*toolchainContract), + .dependencyConstraints = std::move(*dependencyConstraints), .dependencies = std::move(*dependencies), .artifact = {.name = std::move(*artifactName), .url = std::move(*artifactUrl), @@ -769,6 +835,7 @@ namespace Void::Update value.artifact.sha256 != entry.artifactSha256 || value.activation != entry.activation || value.pluginId != entry.pluginId || value.kind != entry.kind || + value.dependencyConstraints != entry.dependencyConstraints || value.dependencies.size() != entry.dependencies.size()) { return Void::Result::fail(std::format( "Component set: release {} does not match the catalog", diff --git a/tests/standalone/Update/Update.cpp b/tests/standalone/Update/Update.cpp index 6621416..0d523be 100644 --- a/tests/standalone/Update/Update.cpp +++ b/tests/standalone/Update/Update.cpp @@ -151,10 +151,13 @@ namespace "kind": "{}", "componentVersion": "{}", "sourceSha": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "sourceTreeHash": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", - "abiHash": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", + "sourceTreeHash": "git-sha1:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "abiHash": {}, "artifactIdentity": "{}-{}-linux-x86_64", "activation": "restart-required", + "platform": "linux", + "architecture": "x86_64", + "toolchainContract": "linux-x86_64-glibc-2.35-cxx26", "dependencies": {}, "artifact": {{ "name": "{}-{}.tar.zst", @@ -166,7 +169,11 @@ namespace }} }})json", componentId, componentId == "Api" ? "sdk" : "runtime-module", - version, componentId, version, dependencies, componentId, version, + version, + componentId == "Api" + ? "null" + : R"("sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")", + componentId, version, dependencies, componentId, version, componentId, version, artifactHash); } } // namespace @@ -242,6 +249,16 @@ Void::Testing::Test component_feed_verifies_and_resolves_complete_set() "{}")); Void::Testing::require(host.has_value()); Void::Testing::require(api.has_value()); + Void::Testing::expect(!api->abiHash.has_value()); + Void::Testing::require(host->abiHash.has_value()); + Void::Testing::expect_eq(*host->abiHash, + std::string{"sha256:" + "ccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccc"}); + Void::Testing::expect_eq( + host->sourceTreeHash, + std::string{"git-sha1:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"}); + Void::Testing::expect_eq(host->platform, std::string{"linux"}); std::map releases; releases.emplace("Api", *api); releases.emplace("Host", *host);