Validate mime type of animated stickers.

This commit is contained in:
John Preston 2019-05-27 14:57:26 +02:00
parent c4aac5fa0e
commit 3577e71782
5 changed files with 61 additions and 65 deletions

View File

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
constexpr auto kMemoryForCache = 32 * 1024 * 1024;
const auto kAnimatedStickerDimensions = QSize(512, 512);
using FilePathResolve = DocumentData::FilePathResolve;
@ -307,9 +308,9 @@ void DocumentOpenClickHandler::Open(
if (QImageReader(path).canRead()) {
Core::App().showDocument(data, context);
return;
} else if (Lottie::ValidateFile(path)) {
Core::App().showDocument(data, context);
return;
//} else if (Lottie::ValidateFile(path)) {
// Core::App().showDocument(data, context);
// return;
}
}
LaunchWithWarning(location.name(), context);
@ -554,14 +555,13 @@ void DocumentData::setattributes(
void DocumentData::validateLottieSticker() {
if (type == FileDocument
&& (_filename.endsWith(qstr(".tgs"))
|| _filename == qstr("animation.json")
|| ((_filename.size() == 9 || _filename.size() == 10)
&& _filename.endsWith(qstr(".json"))
&& QRegularExpression("^\\d+\\.json$").match(_filename).hasMatch()))) {
&& _filename.endsWith(qstr(".tgs"))
&& _mimeString == qstr("application/x-tgsticker")
&& _thumbnail) {
type = StickerDocument;
_additional = std::make_unique<StickerData>();
dimensions = QSize(512, 512);
sticker()->animated = true;
dimensions = kAnimatedStickerDimensions;
}
}
@ -1090,7 +1090,7 @@ void DocumentData::checkStickerLarge() {
if (!data) return;
automaticLoad(stickerSetOrigin(), nullptr);
if (!data->image && loaded()) {
if (!data->image && !data->animated && loaded()) {
if (_data.isEmpty()) {
const auto &loc = location(true);
if (loc.accessEnable()) {

View File

@ -52,6 +52,7 @@ struct StickerData : public DocumentAdditionalData {
Data::FileOrigin setOrigin() const;
std::unique_ptr<Image> image;
bool animated = false;
QString alt;
MTPInputStickerSet set = MTP_inputStickerSetEmpty();
StorageImageLocation loc; // doc thumb location

View File

@ -2446,7 +2446,6 @@ void Session::documentApplyFields(
if (!date) {
return;
}
document->setattributes(attributes);
if (dc != 0 && access != 0) {
document->setRemoteLocation(dc, access, fileReference);
}
@ -2455,6 +2454,7 @@ void Session::documentApplyFields(
document->updateThumbnails(thumbnailInline, thumbnail);
document->size = size;
document->recountIsImage();
document->setattributes(attributes);
if (document->sticker()
&& !document->sticker()->loc.valid()
&& thumbLocation.valid()) {

View File

@ -123,19 +123,13 @@ void HistorySticker::unloadLottie() {
}
void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
if (!_lottie
&& (_data->filename().endsWith(qstr(".tgs"))
|| _data->filename().endsWith(qstr(".json")))) {
if (_data->loaded()) {
const_cast<HistorySticker*>(this)->setupLottie();
} else {
_data->automaticLoad(_parent->data()->fullId(), _parent->data());
}
}
auto sticker = _data->sticker();
if (!sticker) return;
if (sticker->animated && !_lottie && _data->loaded()) {
const_cast<HistorySticker*>(this)->setupLottie();
}
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
_data->checkStickerLarge();
@ -157,47 +151,48 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, c
}
if (rtl()) usex = width() - usex - usew;
if (_lottie) {
if (_lottie->ready()) {
auto request = Lottie::FrameRequest();
request.resize = QSize(_pixw, _pixh) * cIntRetinaFactor();
if (selected) {
request.colored = st::msgStickerOverlay->c;
}
_lottie->markFrameShown();
p.drawImage(
QRect(usex + (usew - _pixw) / 2, (minHeight() - _pixh) / 2, _pixw, _pixh),
_lottie->frame(request));
const auto lottieReady = (_lottie && _lottie->ready());
const auto &pixmap = [&]() -> const QPixmap & {
const auto o = item->fullId();
const auto w = _pixw;
const auto h = _pixh;
const auto &c = st::msgStickerOverlay;
static QPixmap empty;
if (lottieReady) {
return empty;
} else if (const auto image = _data->getStickerLarge()) {
return selected
? image->pixColored(o, c, w, h)
: image->pix(o, w, h);
//
// Inline thumbnails can't have alpha channel.
//
//} else if (const auto blurred = _data->thumbnailInline()) {
// return selected
// ? blurred->pixBlurredColored(o, c, w, h)
// : blurred->pixBlurred(o, w, h);
} else if (const auto thumbnail = _data->thumbnail()) {
return selected
? thumbnail->pixBlurredColored(o, c, w, h)
: thumbnail->pixBlurred(o, w, h);
} else {
return empty;
}
} else {
const auto &pixmap = [&]() -> const QPixmap & {
const auto o = item->fullId();
const auto w = _pixw;
const auto h = _pixh;
const auto &c = st::msgStickerOverlay;
if (const auto image = _data->getStickerLarge()) {
return selected
? image->pixColored(o, c, w, h)
: image->pix(o, w, h);
//
// Inline thumbnails can't have alpha channel.
//
//} else if (const auto blurred = _data->thumbnailInline()) {
// return selected
// ? blurred->pixBlurredColored(o, c, w, h)
// : blurred->pixBlurred(o, w, h);
} else if (const auto thumbnail = _data->thumbnail()) {
return selected
? thumbnail->pixBlurredColored(o, c, w, h)
: thumbnail->pixBlurred(o, w, h);
} else {
static QPixmap empty;
return empty;
}
}();
}();
if (!pixmap.isNull()) {
p.drawPixmap(
QPoint{ usex + (usew - _pixw) / 2, (minHeight() - _pixh) / 2 },
pixmap);
} else if (lottieReady) {
auto request = Lottie::FrameRequest();
request.resize = QSize(_pixw, _pixh) * cIntRetinaFactor();
if (selected) {
request.colored = st::msgStickerOverlay->c;
}
_lottie->markFrameShown();
p.drawImage(
QRect(usex + (usew - _pixw) / 2, (minHeight() - _pixh) / 2, _pixw, _pixh),
_lottie->frame(request));
}
if (!inWebPage) {
auto fullRight = usex + usew;

View File

@ -1842,13 +1842,13 @@ void OverlayWidget::displayDocument(DocumentData *doc, HistoryItem *item) {
const auto &path = location.name();
if (QImageReader(path).canRead()) {
_current = PrepareStaticImage(path);
} else if (auto lottie = Lottie::FromFile(path)) {
_lottie = std::make_unique<LottieFile>(
std::move(lottie));
_lottie->data->updates(
) | rpl::start_with_next([=] {
update();
}, lifetime());
//} else if (auto lottie = Lottie::FromFile(path)) {
// _lottie = std::make_unique<LottieFile>(
// std::move(lottie));
// _lottie->data->updates(
// ) | rpl::start_with_next([=] {
// update();
// }, lifetime());
}
}
location.accessDisable();