From 7d71b08defc121e5e4bac1311fe9453969315588 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 6 Oct 2026 19:46:59 +0200 Subject: [PATCH] Validate avatar object types and distinguish original downloads --- tools/chatgui/src/avatars/avatarcache.cpp | 8 ++++++-- tools/chatgui/src/avatars/avatarmanager.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/chatgui/src/avatars/avatarcache.cpp b/tools/chatgui/src/avatars/avatarcache.cpp index ff76251a..16d70121 100644 --- a/tools/chatgui/src/avatars/avatarcache.cpp +++ b/tools/chatgui/src/avatars/avatarcache.cpp @@ -59,12 +59,16 @@ AvatarCache::Result AvatarCache::readObject(const QString& path, const QString& !mf_avatar_file_valid(r.preview.toLatin1().constData()) || !r.preview.endsWith(".webp") || !r.size.isValid() || qint64(r.size.width()) * r.size.height() > 16 * 1024 * 1024 || r.originalBytes < 1 || r.originalBytes > OriginalMaxBytes || r.previewBytes < 1 || r.previewBytes > MaxBytes || - !r.crop.isValid() || !QRectF(0, 0, 1, 1).contains(r.crop) || qAbs(pixelW - pixelH) > 2) result.error = "invalid avatar manifest"; + !r.crop.isValid() || !QRectF(0, 0, 1, 1).contains(r.crop) || qAbs(pixelW - pixelH) > 2) { + result.error = "invalid avatar manifest"; r = {}; + } } else { QBuffer buffer; buffer.setData(bytes); buffer.open(QIODevice::ReadOnly); QImageReader reader(&buffer); reader.setAutoTransform(true); const QSize size = reader.size(); if (!size.isValid() || qint64(size.width()) * size.height() > 16 * 1024 * 1024 || - (reader.format() != "png" && reader.format() != "jpeg" && reader.format() != "webp")) { + (reader.format() != "png" && reader.format() != "jpeg" && reader.format() != "webp") || + (name.endsWith(".webp") && reader.format() != "webp") || (name.endsWith(".png") && reader.format() != "png") || + (name.endsWith(".jpg") && reader.format() != "jpeg")) { result.error = "invalid image format/dimensions"; return result; } if (qMax(size.width(), size.height()) > 2048) reader.setScaledSize(size.scaled(2048, 2048, Qt::KeepAspectRatio)); diff --git a/tools/chatgui/src/avatars/avatarmanager.cpp b/tools/chatgui/src/avatars/avatarmanager.cpp index 65dd8102..b7528d62 100644 --- a/tools/chatgui/src/avatars/avatarmanager.cpp +++ b/tools/chatgui/src/avatars/avatarmanager.cpp @@ -307,10 +307,10 @@ void AvatarManager::scheduleOwn(quint64 group) { void AvatarManager::enqueue(const Job& job) { for (const auto& old : m_jobs) if ((old.upload == job.upload && old.ref.group == job.ref.group && old.ref.owner == job.ref.owner && - (job.upload || old.ref.hash == job.ref.hash)) || + (job.upload || (old.ref.hash == job.ref.hash && old.original == job.original))) || (!job.upload && !old.upload && old.ref.hash == job.ref.hash && old.original == job.original)) return; for (const auto& old : m_queue) if ((old.upload == job.upload && old.ref.group == job.ref.group && old.ref.owner == job.ref.owner && - (job.upload || old.ref.hash == job.ref.hash)) || + (job.upload || (old.ref.hash == job.ref.hash && old.original == job.original))) || (!job.upload && !old.upload && old.ref.hash == job.ref.hash && old.original == job.original)) return; if (job.upload) m_queue.prepend(job); else m_queue.enqueue(job); }