Browse Source

Validate avatar object types and distinguish original downloads

master
evgeny 6 days ago
parent
commit
7d71b08def
  1. 8
      tools/chatgui/src/avatars/avatarcache.cpp
  2. 4
      tools/chatgui/src/avatars/avatarmanager.cpp

8
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));

4
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);
}

Loading…
Cancel
Save