mirror of https://github.com/procxx/kepka.git
Fix crash on invalid image data.
This commit is contained in:
parent
4695ebae6e
commit
423ea5b499
|
@ -320,6 +320,9 @@ namespace App {
|
|||
}
|
||||
|
||||
QImage readImage(QByteArray data, QByteArray *format, bool opaque, bool *animated) {
|
||||
if (data.isEmpty()) {
|
||||
return QImage();
|
||||
}
|
||||
QByteArray tmpFormat;
|
||||
QImage result;
|
||||
QBuffer buffer(&data);
|
||||
|
|
|
@ -177,6 +177,9 @@ public:
|
|||
[[nodiscard]] QByteArray inlineThumbnailBytes() const {
|
||||
return _inlineThumbnailBytes;
|
||||
}
|
||||
void clearInlineThumbnailBytes() {
|
||||
_inlineThumbnailBytes = QByteArray();
|
||||
}
|
||||
|
||||
[[nodiscard]] Storage::Cache::Key goodThumbnailCacheKey() const;
|
||||
[[nodiscard]] bool goodThumbnailChecked() const;
|
||||
|
|
|
@ -171,9 +171,14 @@ void DocumentMedia::setGoodThumbnail(QImage thumbnail) {
|
|||
|
||||
Image *DocumentMedia::thumbnailInline() const {
|
||||
if (!_inlineThumbnail) {
|
||||
auto image = Images::FromInlineBytes(_owner->inlineThumbnailBytes());
|
||||
if (!image.isNull()) {
|
||||
_inlineThumbnail = std::make_unique<Image>(std::move(image));
|
||||
const auto bytes = _owner->inlineThumbnailBytes();
|
||||
if (!bytes.isEmpty()) {
|
||||
auto image = Images::FromInlineBytes(bytes);
|
||||
if (image.isNull()) {
|
||||
_owner->clearInlineThumbnailBytes();
|
||||
} else {
|
||||
_inlineThumbnail = std::make_unique<Image>(std::move(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
return _inlineThumbnail.get();
|
||||
|
@ -360,10 +365,11 @@ Image *DocumentMedia::getStickerSmall() {
|
|||
}
|
||||
|
||||
void DocumentMedia::checkStickerLarge(not_null<FileLoader*> loader) {
|
||||
if (_owner->sticker()
|
||||
&& !_sticker
|
||||
&& !loader->imageData().isNull()) {
|
||||
_sticker = std::make_unique<Image>(loader->imageData());
|
||||
if (_sticker || !_owner->sticker()) {
|
||||
return;
|
||||
}
|
||||
if (auto image = loader->imageData(); !image.isNull()) {
|
||||
_sticker = std::make_unique<Image>(std::move(image));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,9 @@ public:
|
|||
[[nodiscard]] QByteArray inlineThumbnailBytes() const {
|
||||
return _inlineThumbnailBytes;
|
||||
}
|
||||
void clearInlineThumbnailBytes() {
|
||||
_inlineThumbnailBytes = QByteArray();
|
||||
}
|
||||
|
||||
void load(
|
||||
Data::FileOrigin origin,
|
||||
|
|
|
@ -34,9 +34,14 @@ not_null<PhotoData*> PhotoMedia::owner() const {
|
|||
|
||||
Image *PhotoMedia::thumbnailInline() const {
|
||||
if (!_inlineThumbnail) {
|
||||
auto image = Images::FromInlineBytes(_owner->inlineThumbnailBytes());
|
||||
if (!image.isNull()) {
|
||||
_inlineThumbnail = std::make_unique<Image>(std::move(image));
|
||||
const auto bytes = _owner->inlineThumbnailBytes();
|
||||
if (!bytes.isEmpty()) {
|
||||
auto image = Images::FromInlineBytes(bytes);
|
||||
if (image.isNull()) {
|
||||
_owner->clearInlineThumbnailBytes();
|
||||
} else {
|
||||
_inlineThumbnail = std::make_unique<Image>(std::move(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
return _inlineThumbnail.get();
|
||||
|
|
|
@ -112,7 +112,9 @@ Image::Image(const QString &path) : Image(ReadContent(path)) {
|
|||
Image::Image(const QByteArray &content) : Image(ReadImage(content)) {
|
||||
}
|
||||
|
||||
Image::Image(QImage &&data) : _data(std::move(data)) {
|
||||
Image::Image(QImage &&data)
|
||||
: _data(data.isNull() ? Empty()->original() : std::move(data)) {
|
||||
Expects(!_data.isNull());
|
||||
}
|
||||
|
||||
not_null<Image*> Image::Empty() {
|
||||
|
|
Loading…
Reference in New Issue