mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
Check value size before putting to cache db.
This commit is contained in:
parent
9ba331693f
commit
4b87363a20
7 changed files with 40 additions and 24 deletions
|
@ -354,6 +354,8 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
|
|||
}
|
||||
if (image->savedData().isEmpty()) {
|
||||
image->forget();
|
||||
} else if (image->savedData().size() > Storage::kMaxFileInMemory) {
|
||||
return;
|
||||
}
|
||||
Auth().data().cache().putIfEmpty(
|
||||
Data::StorageCacheKey(key),
|
||||
|
|
|
@ -2340,6 +2340,9 @@ void FormController::fillDownloadedFile(
|
|||
return;
|
||||
}
|
||||
const auto &bytes = i->uploadData->bytes;
|
||||
if (bytes.size() > Storage::kMaxFileInMemory) {
|
||||
return;
|
||||
}
|
||||
Auth().data().cache().put(
|
||||
Data::DocumentCacheKey(destination.dcId, destination.id),
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
|
|
|
@ -53,10 +53,21 @@ inline Error Error::NoError() {
|
|||
|
||||
namespace details {
|
||||
|
||||
using RecordType = uint8;
|
||||
using PlaceId = std::array<uint8, 7>;
|
||||
using EntrySize = std::array<uint8, 3>;
|
||||
using RecordsCount = std::array<uint8, 3>;
|
||||
|
||||
constexpr auto kRecordSizeUnknown = size_type(-1);
|
||||
constexpr auto kRecordSizeInvalid = size_type(-2);
|
||||
constexpr auto kBundledRecordsLimit
|
||||
= size_type(1 << (RecordsCount().size() * 8));
|
||||
constexpr auto kDataSizeLimit = size_type(1 << (EntrySize().size() * 8));
|
||||
|
||||
struct Settings {
|
||||
size_type maxBundledRecords = 16 * 1024;
|
||||
size_type readBlockSize = 8 * 1024 * 1024;
|
||||
size_type maxDataSize = 10 * 1024 * 1024;
|
||||
size_type maxDataSize = (kDataSizeLimit - 1);
|
||||
crl::time_type writeBundleDelay = 15 * 60 * crl::time_type(1000);
|
||||
size_type staleRemoveChunk = 256;
|
||||
|
||||
|
@ -103,16 +114,6 @@ QString VersionFilePath(const QString &base);
|
|||
base::optional<Version> ReadVersionValue(const QString &base);
|
||||
bool WriteVersionValue(const QString &base, Version value);
|
||||
|
||||
using RecordType = uint8;
|
||||
using PlaceId = std::array<uint8, 7>;
|
||||
using EntrySize = std::array<uint8, 3>;
|
||||
using RecordsCount = std::array<uint8, 3>;
|
||||
|
||||
constexpr auto kRecordSizeUnknown = size_type(-1);
|
||||
constexpr auto kRecordSizeInvalid = size_type(-2);
|
||||
constexpr auto kBundledRecordsLimit = (1 << (RecordsCount().size() * 8));
|
||||
constexpr auto kDataSizeLimit = (1 << (EntrySize().size() * 8));
|
||||
|
||||
template <typename Record>
|
||||
constexpr auto GoodForEncryption = ((sizeof(Record) & 0x0F) == 0);
|
||||
|
||||
|
|
|
@ -971,11 +971,13 @@ bool mtpFileLoader::feedPart(int offset, bytes::const_span buffer) {
|
|||
|| _locationType == UnknownFileLocation
|
||||
|| _toCache == LoadToCacheAsWell) {
|
||||
if (const auto key = cacheKey()) {
|
||||
Auth().data().cache().put(
|
||||
*key,
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
base::duplicate(_data),
|
||||
_cacheTag));
|
||||
if (_data.size() <= Storage::kMaxFileInMemory) {
|
||||
Auth().data().cache().put(
|
||||
*key,
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
base::duplicate(_data),
|
||||
_cacheTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1197,11 +1199,13 @@ void webFileLoader::onFinished(const QByteArray &data) {
|
|||
|
||||
if (_localStatus == LocalStatus::NotFound) {
|
||||
if (const auto key = cacheKey()) {
|
||||
Auth().data().cache().put(
|
||||
*key,
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
base::duplicate(_data),
|
||||
_cacheTag));
|
||||
if (_data.size() <= Storage::kMaxFileInMemory) {
|
||||
Auth().data().cache().put(
|
||||
*key,
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
base::duplicate(_data),
|
||||
_cacheTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
_downloader->taskFinished().notify();
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "storage/file_upload.h"
|
||||
|
||||
#include "storage/localimageloader.h"
|
||||
#include "storage/file_download.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -126,7 +127,8 @@ void Uploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &media)
|
|||
: Auth().data().document(media.document, media.photoThumbs.begin().value());
|
||||
if (!media.data.isEmpty()) {
|
||||
document->setData(media.data);
|
||||
if (document->saveToCache()) {
|
||||
if (document->saveToCache()
|
||||
&& media.data.size() <= Storage::kMaxFileInMemory) {
|
||||
Auth().data().cache().put(
|
||||
document->cacheKey(),
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
|
@ -155,7 +157,8 @@ void Uploader::upload(
|
|||
document->uploadingData = std::make_unique<Data::UploadState>(document->size);
|
||||
if (!file->content.isEmpty()) {
|
||||
document->setData(file->content);
|
||||
if (document->saveToCache()) {
|
||||
if (document->saveToCache()
|
||||
&& file->content.size() <= Storage::kMaxFileInMemory) {
|
||||
Auth().data().cache().put(
|
||||
document->cacheKey(),
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
|
|
|
@ -3011,6 +3011,7 @@ Storage::Cache::Database::Settings cacheSettings() {
|
|||
result.clearOnWrongKey = true;
|
||||
result.totalSizeLimit = _cacheTotalSizeLimit;
|
||||
result.totalTimeLimit = _cacheTotalTimeLimit;
|
||||
result.maxDataSize = Storage::kMaxFileInMemory;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1021,7 +1021,9 @@ void RemoteImage::setImageBytes(
|
|||
_forgot = false;
|
||||
|
||||
const auto location = this->location();
|
||||
if (!location.isNull() && !bytes.isEmpty()) {
|
||||
if (!location.isNull()
|
||||
&& !bytes.isEmpty()
|
||||
&& bytes.size() <= Storage::kMaxFileInMemory) {
|
||||
Auth().data().cache().putIfEmpty(
|
||||
Data::StorageCacheKey(location),
|
||||
Storage::Cache::Database::TaggedValue(
|
||||
|
|
Loading…
Add table
Reference in a new issue