From f8034b843a1b07347156d5fbb9aa5a7eddaa2988 Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 15 Jul 2026 10:09:00 -0500 Subject: [PATCH] fix(contacts): stricter path guard in pruneOrphanAvatar Compare the file's parent path to the managed dir instead of a string prefix, so a sibling dir like contact-avatars-x can't false-match. Our avatar copies always live directly in the dir, so this is both correct and safer. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/ui/windows/contacts_tab.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/windows/contacts_tab.cpp b/src/ui/windows/contacts_tab.cpp index 790bfec..08aa83a 100644 --- a/src/ui/windows/contacts_tab.cpp +++ b/src/ui/windows/contacts_tab.cpp @@ -169,8 +169,9 @@ static void pruneOrphanAvatar(const std::string& oldAvatar, const data::AddressB const std::string path = oldAvatar.substr(4); fs::path managed = fs::weakly_canonical(fs::path(util::Platform::getConfigDir()) / "contact-avatars", ec); fs::path target = fs::weakly_canonical(fs::path(path), ec); - // Only prune files actually inside the managed dir (guards against a hand-edited external path). - if (managed.empty() || target.string().rfind(managed.string(), 0) != 0) return; + // Only prune files sitting DIRECTLY in the managed dir (copyAvatarImage never nests) — a parent-path + // compare avoids string-prefix false matches (e.g. a sibling "contact-avatars-x") and path escapes. + if (managed.empty() || target.parent_path() != managed) return; fs::remove(target, ec); invalidateAvatarTexture(path); }