Attempt to fix crash in story preloading.

This commit is contained in:
John Preston 2023-07-25 20:50:21 +04:00
parent 35f0f87f73
commit 30334b6c74
5 changed files with 9 additions and 4 deletions

View File

@ -54,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
constexpr auto kDefaultCoverThumbnailSize = 100;
constexpr auto kMaxAllowedPreloadPrefix = 6 * 1024 * 1024;
const auto kLottieStickerDimensions = QSize(
kStickerSideSize,
@ -393,7 +394,7 @@ void DocumentData::setattributes(
if (data.is_round_message()) {
_additional = std::make_unique<RoundData>();
} else if (const auto size = data.vpreload_prefix_size()) {
if (size->v > 0) {
if (size->v > 0 && size->v < kMaxAllowedPreloadPrefix) {
_videoPreloadPrefix = size->v;
}
}

View File

@ -217,7 +217,7 @@ public:
void registerPolling(not_null<Story*> story, Polling polling);
void unregisterPolling(not_null<Story*> story, Polling polling);
bool registerPolling(FullStoryId id, Polling polling);
[[nodiscard]] bool registerPolling(FullStoryId id, Polling polling);
void unregisterPolling(FullStoryId id, Polling polling);
void requestUserStories(
not_null<UserData*> user,

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "media/streaming/media_streaming_reader.h"
#include "storage/download_manager_mtproto.h"
#include "storage/file_download.h" // kMaxFileInMemory
#include "ui/text/text_utilities.h"
namespace Data {
@ -574,6 +575,7 @@ void StoryPreload::load() {
}
_task = std::make_unique<LoadTask>(id(), video, [=](QByteArray data) {
if (!data.isEmpty()) {
Assert(data.size() < Storage::kMaxFileInMemory);
_story->owner().cacheBigFile().putIfEmpty(
key,
Storage::Cache::Database::TaggedValue(std::move(data), 0));

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lottie/lottie_frame_generator.h"
#include "ffmpeg/ffmpeg_frame_generator.h"
#include "chat_helpers/stickers_lottie.h"
#include "storage/file_download.h" // kMaxFileInMemory
#include "ui/widgets/input_fields.h"
#include "ui/text/text_custom_emoji.h"
#include "ui/text/text_utilities.h"
@ -345,7 +346,7 @@ void CustomEmojiLoader::check() {
};
auto put = [=, key = cacheKey(document)](QByteArray value) {
const auto size = value.size();
if (size <= Storage::Cache::Database::Settings().maxDataSize) {
if (size <= Storage::kMaxFileInMemory) {
document->owner().cacheBigFile().put(key, std::move(value));
} else {
LOG(("Data Error: Cached emoji size too big: %1.").arg(size));

View File

@ -283,9 +283,10 @@ BaseLayout *Provider::getLayout(
if (auto layout = createLayout(id, delegate)) {
layout->initDimensions();
it = _layouts.emplace(id, std::move(layout)).first;
_peer->owner().stories().registerPolling(
const auto ok = _peer->owner().stories().registerPolling(
{ _peer->id, id },
Data::Stories::Polling::Chat);
Assert(ok);
} else {
return nullptr;
}