From: Joel Rosdahl Date: Mon, 27 Apr 2026 16:58:32 +0000 (+0200) Subject: fix: Verify cache entry type before parsing manifest or result X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c10c468f44dd519f538c0ace8115d5cddd45fb65;p=thirdparty%2Fccache.git fix: Verify cache entry type before parsing manifest or result Manifest and result cache entry keys should never collide, but handle collision properly if they do anyway. --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index d4fe5de4..2111b874 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -892,6 +892,12 @@ read_manifest(Context& ctx, std::span cache_entry_data) { try { core::CacheEntry cache_entry(cache_entry_data); + if (cache_entry.header().entry_type != core::CacheEntryType::manifest) { + throw core::Error( + FMT("expected cache entry type {} (manifest), actual {}", + static_cast(core::CacheEntryType::manifest), + static_cast(cache_entry.header().entry_type))); + } cache_entry.verify_checksum(); ctx.manifest.read(cache_entry.payload()); } catch (const core::Error& e) { @@ -2641,6 +2647,12 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Hash::Digest& result_key) try { core::CacheEntry cache_entry(cache_entry_data); + if (cache_entry.header().entry_type != core::CacheEntryType::result) { + throw core::Error( + FMT("expected cache entry type {} (result), actual {}", + static_cast(core::CacheEntryType::result), + static_cast(cache_entry.header().entry_type))); + } cache_entry.verify_checksum(); core::result::Deserializer deserializer(cache_entry.payload()); core::ResultRetriever result_retriever(ctx, result_key);